<style>
/* 日历的样式开始 */
.calendar
{
background-color: #FFFFFF;
border: 1px solid #003366;
}
/* 第一行: 年份月份和导航 */
.calendar .title
{
background-image: url("/theme/monthbg.gif");
line-height: 110%;
background-color: #D8E2EC;
text-align: center;
vertical-align: middle;
font-family: Geneva, Verdana, Arial, sans-serif;
font-size: 15px;
font-weight: Bold;
color: #252216;
}
/* 第二行: 星期几 */
.calendar .head
{
background-color: #F5F4D3;
font-family: Geneva, Verdana, Arial, sans-serif;
font-size: 15px;
font-weight: Bold;
color: #433D27;
}
/* 每天一个单元格 */
.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)
{
global $theme_dir;
$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);
$prevm=mktime(0, 0, 0, date('m', $time)-1, 1, date('Y', $time));
$nextm=mktime(0, 0, 0, date('m', $time)+1, 1, date('Y', $time));
$prevy=mktime(0, 0, 0, date('m', $time), 1, date('Y', $time)-1);
$nexty=mktime(0, 0, 0, date('m', $time), 1, date('Y', $time)+1);
$url=$_SERVER['PHP_SELF'].'?time=';
$str = '';
$str .= <<<END
<table class="calendar" cellspacing="1">
<tr class="title">
<th><a href="{$url}{$prevy}"><img src="{$theme_dir}backward.gif" border="0" alt="上一年" /></a></th>
<th><a href="{$url}{$prevm}"><img src="{$theme_dir}prev.gif" border="0" alt="上一月" /></a></th>
<th colspan="3">{$title}</td>
<th><a href="{$url}{$nextm}"><img src="{$theme_dir}next.gif" border="0" alt="下一月" /></a></th>
<th><a href="{$url}{$nexty}"><img src="{$theme_dir}forward.gif" border="0" alt="下一年" /></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', $time)) $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;
}
// 使用范例
echo calendar(time());
?>
运行效果见http://www.geofuture.net