您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP简单日历实现方法

2024/5/29 8:55:58发布35次查看
这篇文章主要介绍了php简单日历实现方法,涉及php日期与时间的相关运算操作,非常简单实用,需要的朋友可以参考下
运行效果截图如下:
具体代码如下:
<?php/* * created on 2016-7-20 */simcalendar('2016-08');//显示8月份日历function simcalendar($date){ /** * 简单日历输出,本函数需要cal_days_in_month的支持 * @param $date y-m 要输出的日期 */ echo '<table border="1"> <thead> <tr> <th>日</th> <th>一</th> <th>二</th> <th>三</th> <th>四</th> <th>五</th> <th>六</th> </tr> </thead> <tbody>'; $date_array = explode('-', $date); $start_week = 0;//从星期天开始为0 $month = cal_days_in_month(cal_gregorian, $date_array[1], $date_array[0]);//当月的天数 $wstar = date('w', strtotime($date . '-01'));//当月从星期几天始 $rows = ceil(($wstar + $month) / 7);//总行数 $mday = 1;//第几天 for ($i = 0; $i < $rows; $i++) { echo '<tr>'; for ($d = 0; $d < 7; $d++) { $nowday = 7 * $i + $d + $start_week; if ($nowday >= $wstar && $mday <= $month) { $temp = date('d', strtotime($date . '-' . $mday)); echo '<td>'.$temp . '</td>'; $mday++; } else { echo '<td> </td>'; } } echo '</tr>'; } echo '</tbody></table>';}?>
更多相关教程请访问 php编程从入门到精通全套视频教程
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product