<?php
//年份
$year = isset($_GET['year']) ? $_GET['year'] : date('y');
//当前月份
$month = isset($_GET['month'])? $_GET['month'] : date('m');
//当前的日
$day = isset($_GET['day']) ? $_GET['day'] : date('d');
//获取当月的天数
$days = date('t', mktime(0,0,0, $month, 1, $year));
//获取当月的1号是星期几
$startweek = date('w', mktime(0,0,0, $month, 1, $year));
echo "当天是{$year}年{$month}月{$day}日,这个月的1号是星期{$startweek}<br>";
//http://localhost/network2/week12/date5.php?year=2017&month=5&day=2
//创建表格
echo '<table border="0px" width="500px" align="center">';
//创建表头
echo '<tr>';
echo '<th style="background-color: darkgrey">星期日</th>';
echo '<th style="background-color: darkgrey">星期一</th>';
echo '<th style="background-color: darkgrey">星期二</th>';
echo '<th style="background-color: darkgrey">星期三</th>';
echo '<th style="background-color: darkgrey">星期四</th>';
echo '<th style="background-color: darkgrey">星期五</th>';
echo '<th style="background-color: darkgrey">星期六</th>';
echo '</tr>';
//通过循环来实现日历内容
echo '<tr>';
//输出空白 1号前面的空白
for($i = 0; $i<$startweek; $i++){
echo '<td> </td>';
}
for($j = 1; $j <= $days; $j++){
echo "<td align='center' >{$j}</td>";
$i++;
//换行
if($i % 7 ==0){
echo '</tr><tr>';
}
}
//作业: 日历
//尾处的留白
while($i%7 !== 0){
echo '<td> </td>';
$i++;
}
echo '</tr>';
echo '</table>';//结束
?>
日历
最新推荐文章于 2024-01-30 10:30:00 发布