我正在整理一个每周视图日历,但到 10 月 28 日时我遇到了问题,这是时钟前进的时间。日历跳过一天
到目前为止我的代码...
//get viewed date from form and add either a week to it or take a week away
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 {
//sets the current day as the first day of the week so no good
/*$display_week_ts = floor(time() / (3600 * 24)) * 3600 * 24;*/
//Does't account for british summer time so days are out after 28th October
$display_week_ts = strtotime("Monday noon");
}
$week_start = new DateTime(date("Y-m-d", $display_week_ts));
for ($i = 0; $i < 7; $i++)
{
echo '<td class="day">';
$current_day_ts = $display_week_ts + ($i * 3600 *24);
$daily_date = date('d-m-Y', $current_day_ts);
$StartDate = date('d', $current_day_ts);
$MonthName = date('m', $current_day_ts);
$Year = date('Y', $current_day_ts);
echo $daily_date;
echo '</td>';
}
$week_start 包含日历中当前视图中的一周开始的值。首次打开时会显示当前周。如果按下下周按钮,则将一周添加到 $week_start 值。目前保存在表格的隐藏字段中,并在提交时回发。我还尝试将 $week_start 作为 TimeDate() 对象存储在会话中
$week_start = new DateTime(date("Y-m-d", $display_week_ts));
$S_SESSION['week_start'] = $week_start;
但是当我尝试回调会话并使用它时,向前移动一周
$week_start = $S_SESSION['week_start'];
$week_start->modify('+1 week');
我收到错误“警告:DateTime::modify() [datetime.modify]:DateTime 对象未由其构造函数正确初始化”。在做了一些挖掘之后,我发现 DateTime 似乎直到 5.3 才支持会话,而我正在使用 5.2.17
如果有人可以帮助我锻炼一种方法,使变量 $week_start 成为由 $display_week_ts 表示的一周的第一天,我将非常感激,这样 BST 不会引起问题。我已经在这方面扎实工作了 3 天了