我想把每个月划分为像图片一样的日子:
我写了一些代码,但我有类似的东西:
<?php
$start_date = date('Y-m-d', strtotime('2015-12-28'));
$end_date = date('Y-m-d', strtotime('2018-01-01'));
$i=1;
for($date = $start_date; $date <= $end_date; $date = date('Y-m-d', strtotime($date. ' + 7 days'))) {
echo getWeekDates($date, $start_date, $end_date, $i);
echo "\n";
$i++;
}
function getWeekDates($date, $start_date, $end_date, $i) {
$week = date('W', strtotime($date));
$year = date('Y', strtotime($date));
$from = date("Y-m-d", strtotime("{$year}-W{$week}+1"));
if($from < $start_date) $from = $start_date;
$to = date("Y-m-d", strtotime("{$year}-W{$week}-7"));
if($to > $end_date) $to = $end_date;
echo "$i. od ".$from." do ".$to.'<br>';
}
?>
输出:
1. od 2015-12-28 do 2016-01-03
2. od 2016-01-04 do 2016-01-10
3. od 2016-01-11 do 2016-01-17
4. od 2016-01-18 do 2016-01-24
我不知道如何排除这个月的一周有1,2,3,4,5或6天的例外情况....
答案 0 :(得分:0)
您可以使用/修改this class来实现您的目标。
代码几乎被评论以理解逻辑。
这是您打印日历的方法。
include 'calendar.php';
$calendar = new Calendar();
echo $calendar->show();