<?
session_start();
header("content-type:text/html; charset=utf-8");
$year = trim($_GET['y']);
$year= ( is_numeric($year) and strlen($year) == 4 ) ? $year : gmdate('Y', time()+8*3600);
$month = trim($_GET['m']);
if ( strlen($month) == 1 ) $month = "0".$month;
$month= ( is_numeric($month) and strlen($month) == 2 ) ? $month : gmdate('m', time()+8*3600);
$days=date('t',strtotime("$year-$month-01"));//获取当前月有多少天
$week=date('w',strtotime("$year-$month-01"));//当前1号是星期几
//实现上一月和上一年
if($month==1){
$premonth = 12;
$preyear = $year - 1;
}else{
$premonth = $month-1;
if ( strlen($premonth) == 1 ) $premonth = "0".$premonth;
$preyear = $year;
}
//实现下一月和下一年
if($month==12){
$nextmonth = "01";
$nextyear = $year + 1;
}else{
$nextmonth = $month + 1;
if ( strlen($nextmonth) == 1 ) $nextmonth = "0".$nextmonth;
$nextyear = $year;
}
?>
<table width="600" border="0" align="center" cellpadding="4" cellspacing="1">
<tr>
<td width="20%"><div align="center"></div></td>
<td>
<div align="center">
<a href="?y=<?=$preyear?>&m=<?=$premonth?>"><<</a>
<b><?=$year?>年<?=$month?>月</b>
<a href="?y=<?=$nextyear?>&m=<?=$nextmonth?>">>></a>
</div></td>
<td width="20%"><div align="center"><a href="?">今天</a></div></td>
</tr>
</table>
<table width="600" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#dddddd">
<tr>
<th bgcolor="#FFFFFF">日</th>
<th bgcolor="#FFFFFF">一</th>
<th bgcolor="#FFFFFF">二</th>
<th bgcolor="#FFFFFF">三</th>
<th bgcolor="#FFFFFF">四</th>
<th bgcolor="#FFFFFF">五</th>
<th bgcolor="#FFFFFF">六</th>
</tr>
<?
for($i=1-$week; $i<=$days;){
echo '<tr>';
for($j=0; $j<7; $j++){
$td_bgcolor = 'bgcolor="#FFFFFF"';
if ( gmdate("Ymd", time()+8*3600) == $year.$month.$i ) $td_bgcolor = 'bgcolor="#D7FFD7"';
$td_color = '';
if ( $j==0 or $j==6 ) $td_color = 'style=" color:red;"';
if( $i>$days or $i<=0 ){
echo '<td height="60" '.$td_bgcolor.' '.$td_color.'> </td>';
}else{
echo '<td height="60" '.$td_bgcolor.' '.$td_color.'>'.$i.'</td>';
}
$i++;
}
echo '</tr>';
}
?>
</table>
session_start();
header("content-type:text/html; charset=utf-8");
$year = trim($_GET['y']);
$year= ( is_numeric($year) and strlen($year) == 4 ) ? $year : gmdate('Y', time()+8*3600);
$month = trim($_GET['m']);
if ( strlen($month) == 1 ) $month = "0".$month;
$month= ( is_numeric($month) and strlen($month) == 2 ) ? $month : gmdate('m', time()+8*3600);
$days=date('t',strtotime("$year-$month-01"));//获取当前月有多少天
$week=date('w',strtotime("$year-$month-01"));//当前1号是星期几
//实现上一月和上一年
if($month==1){
$premonth = 12;
$preyear = $year - 1;
}else{
$premonth = $month-1;
if ( strlen($premonth) == 1 ) $premonth = "0".$premonth;
$preyear = $year;
}
//实现下一月和下一年
if($month==12){
$nextmonth = "01";
$nextyear = $year + 1;
}else{
$nextmonth = $month + 1;
if ( strlen($nextmonth) == 1 ) $nextmonth = "0".$nextmonth;
$nextyear = $year;
}
?>
<table width="600" border="0" align="center" cellpadding="4" cellspacing="1">
<tr>
<td width="20%"><div align="center"></div></td>
<td>
<div align="center">
<a href="?y=<?=$preyear?>&m=<?=$premonth?>"><<</a>
<b><?=$year?>年<?=$month?>月</b>
<a href="?y=<?=$nextyear?>&m=<?=$nextmonth?>">>></a>
</div></td>
<td width="20%"><div align="center"><a href="?">今天</a></div></td>
</tr>
</table>
<table width="600" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#dddddd">
<tr>
<th bgcolor="#FFFFFF">日</th>
<th bgcolor="#FFFFFF">一</th>
<th bgcolor="#FFFFFF">二</th>
<th bgcolor="#FFFFFF">三</th>
<th bgcolor="#FFFFFF">四</th>
<th bgcolor="#FFFFFF">五</th>
<th bgcolor="#FFFFFF">六</th>
</tr>
<?
for($i=1-$week; $i<=$days;){
echo '<tr>';
for($j=0; $j<7; $j++){
$td_bgcolor = 'bgcolor="#FFFFFF"';
if ( gmdate("Ymd", time()+8*3600) == $year.$month.$i ) $td_bgcolor = 'bgcolor="#D7FFD7"';
$td_color = '';
if ( $j==0 or $j==6 ) $td_color = 'style=" color:red;"';
if( $i>$days or $i<=0 ){
echo '<td height="60" '.$td_bgcolor.' '.$td_color.'> </td>';
}else{
echo '<td height="60" '.$td_bgcolor.' '.$td_color.'>'.$i.'</td>';
}
$i++;
}
echo '</tr>';
}
?>
</table>