当前位置:首页 » 操作系统 » php万年历源码

php万年历源码

发布时间: 2023-06-10 02:04:36

① 万年历 源码编辑,修改

1.
var adds
if (perscal[2]>7)
adds = 1230
else
adds = 1130

var timeData = {
"China 中国": {
"BeiJing 北京":["+"+adds,"","北京、重庆、乌鲁木齐"],//伊朗春斗做悉节过后修改胡埋为+1130,6个月后修改为+1230
"Iran 伊朗":["+0800","","德黑兰"]
}
};

2.在HTML里面加一个div,名字随便了 跟着阴历的一起跑,id=随便取一个名字
然后用document.getElementById("id名").innerHTML="内容" 控空乎制

php小白,做的日历有源码,求大神帮看看问题在哪里,感激不尽

代码逻辑就有问题

你的sql循环遍历里截取了一次day应该是无用代码,下面把数据存入数组中写的键名 data 和前面写的date并不一样。你自己检查一下有没有问题。

另外 你的判断日期是否特殊日期的逻辑里,是根据数组索引 $i 来判断的,你能保证从数据库取出的数据是按天排序每天都有的吗?

一般做日期判断可以把数据拉出来按日期索引 ,这样后面日期判断的时候根据键名来判断就比较准确了。

//存入标志数组
$day_color[$row['date']]=true;

for(...){
$date=sprintf("%02d",$i);
if(!empty($day_color['2019-01-'.$date])){
...
}else{
...
}
}

③ 如何用PHP制作日历

calendar.class.php
代码如下:
<?php
classCalendar{
private$year;//当前的年
private$month;//当前的月
private$start_weekday;//当月的第一天对应的是周几
private$days;//当前月一共多少天

function__construct(){
$this->year=isset($_GET["year"])?$_GET["year"]:date("Y");
$this->month=isset($_GET["month"])?$_GET["month"]:date("m");

$this->start_weekday=date("w",mktime(0,0,0,$this->month,1,$this->year));
$this->days=date("t",mktime(0,0,0,$this->month,1,$this->year));
}

functionout(){
echo'<tablealign="center">';
$this->chageDate("test.php");
$this->weeksList();
$this->daysList();
echo'</table>';
}

privatefunctionweeksList(){
$week=array('日','一','二','三','四','五','六');

echo'<tr>';
for($i=0;$i<count($week);$i++)
echo'<thclass="fontb">'.$week[$i].'</th>';

echo'</tr>';
}

privatefunctiondaysList(){
echo'<tr>';
//输出空格(当前一月第一天前面要空出来)
for($j=0;$j<$this->start_weekday;$j++)
echo'<td></td>';


for($k=1;$k<=$this->days;$k++){
$j++;
if($k==date('d'))
echo'<tdclass="fontb">'.$k.'</td>';
else
echo'<td>'.$k.'</td>';

if($j%7==0)
echo'</tr><tr>';

}

//后面几个空格
while($j%7!==0){
echo'<td></td>';
$j++;
}

echo'</tr>';
}

privatefunctionprevYear($year,$month){
$year=$year-1;

if($year<1970)
$year=1970;

return"year={$year}&month={$month}";
}


privatefunctionprevMonth($year,$month){
if($month==1){
$year=$year-1;

if($year<1970)
$year=1970;

$month=12;
}else{
$month--;
}

return"year={$year}&month={$month}";
}


privatefunctionnextYear($year,$month){
$year=$year+1;

if($year>2038)
$year=2038;

return"year={$year}&month={$month}";
}


privatefunctionnextMonth($year,$month){
if($month==12){
$year++;

if($year>2100)
$year=2100;

$month=1;
}else{
$month++;
}


return"year={$year}&month={$month}";
}

privatefunctionchageDate($url=""){
echo'<tr>';
echo'<td><ahref="?'.$this->prevYear($this->year,$this->month).'">'.'<<'.'</a></td>';
echo'<td><ahref="?'.$this->prevMonth($this->year,$this->month).'">'.'<'.'</a></td>';
echo'<tdcolspan="3">';
echo'<form>';
echo'<selectname="year"onchange="window.location=''.$url.'?year='+this.options[selectedIndex].value+'&month='.$this->month.''">';
for($sy=1970;$sy<=2100;$sy++){
$selected=($sy==$this->year)?"selected":"";
echo'<option'.$selected.'value="'.$sy.'">'.$sy.'</option>';
}
echo'</select>';
echo'<selectname="month"onchange="window.location=''.$url.'?year='.$this->year.'&month='+this.options[selectedIndex].value">';
for($sm=1;$sm<=12;$sm++){
$selected1=($sm==$this->month)?"selected":"";
echo'<option'.$selected1.'value="'.$sm.'">'.$sm.'</option>';
}
echo'</select>';
echo'</form>';
echo'</td>';


echo'<td><ahref="?'.$this->nextYear($this->year,$this->month).'">'.'>>'.'</a></td>';
echo'<td><ahref="?'.$this->nextMonth($this->year,$this->month).'">'.'>'.'</a></td>';
echo'</tr>';
}

}
?>test.php

代码如下:
<style>
table{
border:1pxsolid#050;
}

.fontb{
color:white;
background:blue;
}


th{
width:30px;
}

td,th{
height:30px;
text-align:center;

}
form{
margin:0px;
padding:0px;
}
</style>
<?php
include"calendar.class.php";

$calendar=newCalendar;

$calendar->out();
?>

④ php万年历程序代码

PHP代码:

--------------------------------------------------------------------------------

<style>

.calendar
{
background-color: #FFFFFF;
border: 1px solid #003366;
}
.calendar .title
{
background-image: url("/theme/monthbg.gif");
line-height: 17pt;
background-color: #D8E2EC;
text-align: center;
vertical-align: middle;
font-family: Geneva, Verdana, Arial, sans-serif;
font-size: 13px;
font-weight: Bold;
color: #252216;
}
.calendar .head
{
background-image: url("dayBg.gif");
font-family: Geneva, Verdana, Arial, sans-serif;
font-size: 10px;
font-weight: Bold;
color: #433D27;
}
.calendar tbody
{
line-height: 11pt;
background-color: #F5F4D3;
text-align: center;
vertical-align: middle;
}
.calendar td
{
font-family: Geneva, Verdana, Arial, sans-serif;
font-size: 10px;
line-height: 15pt;
text-align: center;
vertical-align: middle;
width: 25px;
}
.calendar .weekday
{
background-color: #e0e0e0;
}
.calendar .weekend
{
background-color: #d0d0d0;
}
.calendar .today
{
background-color: #f7bebd;
}
.calendar .exmonth
{
background-color: #eeeeee;
}
.calendar a
{
text-decoration: none;
cursor: hand;
}
</style>

<?php
// 显示某天所在月份的日历

function calendar($time)
{
$start=mktime(0, 0, 0, date('m', $time), 1, date('Y', $time));
$start=$start-date('w', $start)*86400; // extent to start of week
$end=mktime(0, 0, 0, date('m', $time)+1, 1, date('Y', $time));
$end=$end+(7-date('w', $end))*86400; // extent to end of week
//$sWeekday=array('日','一','二','三','四','五','六');
$sWeekday=array('S','M','T','W','T','F','S');
$title=date('M Y', $time);
$prev=mktime(0, 0, 0, date('m', $time)-1, 1, date('Y', $time));
$next=mktime(0, 0, 0, date('m', $time)+1, 1, date('Y', $time));
$url=$_SERVER['PHP_SELF'].'?time=';

$str = '';
$str .= <<<END
<table class="calendar" cellspacing="1">
<tr class="title">
<th colspan="2"><a href="{$url}{$prev}"><<</a></th>
<th colspan="3">{$title}</td>
<th colspan="2"><a href="{$url}{$next}">>></a></th>
</tr>
<tr class="head">
<th>{$sWeekday[0]}</td>
<th>{$sWeekday[1]}</td>
<th>{$sWeekday[2]}</td>
<th>{$sWeekday[3]}</td>
<th>{$sWeekday[4]}</td>
<th>{$sWeekday[5]}</td>
<th>{$sWeekday[6]}</td>
</tr>
<tr>

END;

for($stamp=$start;$stamp<$end;$stamp+=86400) // loop through each day, which is 86400 seconds
{
$weekday=date('w', $stamp);
if(date('m', $stamp)!=date('m', $time)) $style='exmonth';
else if(date('Y-m-d', $stamp)==date('Y-m-d')) $style='today';
else if(date('w', $stamp)==0 || date('w', $stamp)==6) $style='weekend';
else $style='weekday';
$str.= "\t\t".'<td class="'.$style.'"><a href="'.$url.$stamp.'">'.sprintf('%d',date('d', $stamp)).'</a></td>'."\n";
if(date('w', $stamp)==6) $str.="\t".'</tr>'."\n";
}

$str .= '</table>';
return $str;
}
?>

⑤ php中将一年12个月的日历全部输出。如何做

<?php
//SKY8G提供
function cal_days_in_year($year){
$days=0;
for($month=1;$month<=12;$month++){
$days = $days + cal_days_in_month(CAL_GREGORIAN,$month,$year);
}
return $days;
}
//闰年
echo "这是闰年一年有:".cal_days_in_year(2000)."天";
echo "\n";
//平年
echo "这是平年一年有:".cal_days_in_year(1999)."天";
echo "\n";
//2019年
echo "今年2019年有:".cal_days_in_year(date('Y',time()))."天";
echo "\n";
//接下来我们是用php的内置函数cal_days_in_month()
$d=cal_days_in_month(CAL_GREGORIAN,2,2010);
echo "2010 年平年 2 月有 $d 天。\n";
$d=cal_days_in_month(CAL_GREGORIAN,2,2000);
echo "2000 年闰年 2 月有 $d 天。";
echo "\n";
$d=cal_days_in_month(CAL_GREGORIAN,4,2010);
echo "2010 年平年 4 月有 $d 天。\n";
$d=cal_days_in_month(CAL_GREGORIAN,4,2000);
echo "2000 年闰年 4 月有 $d 天。";
echo "\n";
$d=cal_days_in_month(CAL_GREGORIAN,8,2010);
echo "2010 年平年 8 月有 $d 天。\n";
$d=cal_days_in_month(CAL_GREGORIAN,8,2000);
echo "2000 年闰年 8 月有 $d 天。";
//详情如果想了解详情去sky8g网观看,希望对你有帮助!

热点内容
php递归算法经典实例 发布:2025-04-07 03:31:13 浏览:454
字卦的算法 发布:2025-04-07 03:31:11 浏览:694
中国年鉴数据库 发布:2025-04-07 03:11:26 浏览:325
短信发送android 发布:2025-04-07 03:11:19 浏览:396
thinkphp上传多张图片 发布:2025-04-07 03:09:50 浏览:825
12位密码最多猜多少次 发布:2025-04-07 03:08:30 浏览:549
三消的算法 发布:2025-04-07 02:56:27 浏览:822
安卓手机在哪里下载特斯拉 发布:2025-04-07 02:55:41 浏览:62
linux命令启动服务 发布:2025-04-07 02:22:27 浏览:68
sqlserver数据库邮件 发布:2025-04-07 02:06:12 浏览:448