写在前面,日历是从网上找的代码,特此感谢作者!具体地方记不清了
代码在下面:
<style type=text/css>
A:link{
color:#FFFFFF;
font-size:35px;
}
A:visited{
color:#FFFFFF;
text-decoration:none;
}
A:hover{
text-decoration:underline;
}
TD{
text-align:center;
font-size:35px;
background-color:#E6E6E6;
border: #FFFFFF solid 1px;
color:#198281;
height:70px;
}
TD.title{
background-color:#9a9a9a;
color:#FFFFFF;
font-weight:bold;
}
TABLE{
border-collapse:collapse;
border-color:white;
border: #198281 solid 1px;
}
</style>
<?php
date_default_timezone_set(“Asia/Shanghai”);
#$date=strtotime(date(“Y-m-d”));
$jzb=strtotime(“2014-06-06”);//定义一个白班日期并转换为数值
$jzy=strtotime(“2014-06-08”);//定义一个夜班日期并转换为数值
$today = time();
$year =@ $_GET[“year”];
$month = @$_GET[“month”];
if($year==’’) $year = date(“Y”,$today);
if($month==’’) $month = date(“m”,$today);
if((int)$month==0){$year-=1;$month=12;}
$time = mktime(0,0,0,$month,1,$year);
$year = date(’Y’,$time);
$month = date(’m’,$time);
echo “<table width=760 cellspacing=0 cellpadding=0>”;
echo “<tr><td colspan=7 class=title>”;
$str = “<a href=?year=”.($year-1).”&month=”.$month.”>”;
$str .= “«</a> “.$year.”年 “;
$str .= “<a href=?year=”.($year+1).”&month=”.$month.”>”;
$str .= “»</a> “;
$str .= “<a href=?year=”.$year.”&month=”.($month-1).”>”;
$str .= “«</a> “.$month.”月 “;
$str .= “<a href=?year=”.$year.”&month=”.($month+1).”>”;
$str .= “» </a>”;
echo $str;
echo “ ”;
echo ’<a href=”’.$_SERVER[’PHP_SELF’].’”>返回本月</a>’;//返回当前月份
echo “</td></tr>”;
echo “<tr>”;
$str = “<td>一</td>”;
$str .= “<td>二</td>”;
$str .= “<td>三</td>”;
$str .= “<td>四</td>”;
$str .= “<td>五</td>”;
$str .= “<td>六</td>”;
$str .= “<td>日</td>”;
echo $str;
echo “</td>”;
//这个月有多少天
$days = date(’t’,$time);
//第一天是星期几
$fstdw = date(’N’,$time);
//要输出多少行
$rows = ceil(($days + $fstdw-1)/7);
$cd = 1;
#echo $year.”</br>”;
#echo $month.”</br>”;
#echo date(’d’,time()).”</br>”;
for($i=0;$i<$rows;$i++){
echo “<tr>”;
for($j=0;$j<7;$j++){
echo “<td>”;
if($cd >= $fstdw && $cd<$days+$fstdw){
$oday = $cd-$fstdw+1;
if($oday==date(’d’,time()))
echo “<b><u>”;
$data1=($year.”-“.$month.”-“.($cd-$fstdw+1));//定义日历日期
$data2=strtotime($data1);//日期转换为数值
$databai=round(($data2-$jzb)/3600/24%5);//计算日历日期和定义白班日期差值的余数
$dataye=round(($data2-$jzy)/3600/24%5);//计算日历日期和定义夜班日期差值的余数
if($databai==0){//如果白班差值余数为0
echo ($cd-$fstdw+1).”白”;//日期
}elseif($dataye==0){//如果夜班差值余数为0
echo ($cd-$fstdw+1).”夜”;//日期
}else//其他不写白班或者夜班
echo ($cd-$fstdw+1);//日期
}else{
echo ” “;
}
$cd++;
echo “</td>”;
}
echo “</tr>”;
}
echo “</table>”;
?>
方便倒班人士算班,好了,就这样吧!