我有一个脚本,但它不是我需要的(每周星期日开始没有bug)。修改(" -1天")或修改(" +6天")显示我需要的内容,但有时它会相应地导致前一周或下周。 我已经搜索了很多解决方案,但无法得到它。 需要一些帮助。
代码:
<?php
$dt = new DateTime;
if (isset($_GET['year']) && isset($_GET['week'])) {
$dt->setISODate($_GET['year'], $_GET['week']);
} else {
$dt->setISODate($dt->format('o'), $dt->format('W'));
}
$year = $dt->format('o');
$week = $dt->format('W');
/*$dt->modify("-1 days");*/ // This -1 or +6 will make it starts with sunday but sometimes it shows the wrong week.
?>
<div class="next-pre">
<div class="pre-week float-left">
<a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week-1).'&year='.$year; ?>">Pre Week</a>
</div>
<div class="next-week float-right">
<a href="<?php echo $_SERVER['PHP_SELF'].'?week='.($week+1).'&year='.$year; ?>">Next Week</a>
</div>
</div>
<?php
$numDay = 1;
do {
?>
<div class="calender">
<table class="weeks">
<tr>
<?php if($dt->format('d M Y') == date('d M Y')){ ?>
<td class="color cell"><?php echo $dt->format('l'); ?> <strong class="margin5"> <?php echo $dt->format('d M Y'); ?> </strong></td>
<td class="default cell"> </td>
<?php } else{ ?>
<td class="default cell"><?php echo $dt->format('l'); ?> <strong class="margin5"> <?php echo $dt->format('d M Y'); ?> </strong></td>
<td class="default cell"> </td>
<?php } ?>
</tr>
</table>
</div>
<?php
/*echo "<td>" . $dt->format('l') . "<br>" . $dt->format('d M Y') . "</td>\n";*/
$dt->modify('+1 days');
$numDay++;
} while ($numDay<=7);
?>