我正在放在一起每週查看日曆,但我有問題時,到10月28日,這是時鐘前進。日曆跳過一天BST造成與日曆日期的噩夢
到目前爲止我的代碼...
//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()對象保存在session
$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不會導致問題的方式表示。我一直在
完美的是,所有這些日子以及我玩過的所有代碼,我需要做的就是在頁面頂部添加一行代碼。我很感激你,這是開始做我的頭,謝謝你! – tatty27