我正在尝试创建一个允许用户前进或后退一周的周历。到目前为止,我有这个...
<?
if(isset($_POST['add_week'])){
$last_week_ts = strtotime($_POST['last_week']);
$display_week_ts = $last_week_ts + (3600 * 24 * 7);
} else if (isset($_POST['back_week'])) {
$last_week_ts = strtotime($_POST['last_week']);
$display_week_ts = $last_week_ts - (3600 * 24 * 7);
} else {
$display_week_ts = floor(time() / (3600 * 24)) * 3600 * 24;
}
$week_start = date('d-m-Y', $display_week_ts);
$week_number = date("W", strtotime( $display_week_ts));
$year = date("Y", strtotime( $display_week_ts));
echo $week_start.' '.$week_number.' '.$year;
?>
<table name="week">
<tr>
<?
for($day=1; $day<=7; $day++)
{
echo '<td>';
echo date('d-m-Y', strtotime($year."W".$week_number.$day))." | \n";
echo '</td>';
}
?>
</tr>
<tr>
<form name="move_weeks" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="last_week" value="<? echo $week_start; ?>" />
<td colspan="7"><input type="submit" name="back_week" value="back_week" /><input type="submit" name="add_week" value="add_week" />
</td>
</form>
</tr>
</table>
后退和前进按钮工作得很好,代表一周中第一个日期的 $week_start 变量前进并按原样返回,但无论显示的日期如何 $week_number 和 $year 显示为 01 和 1970 或 36 和 1600 .
我知道这一定与我试图从 $display_week_ts 中提取它们的方式有关,但我不知道是什么