我的整個網站是:日期時間不會改變臨時
date_default_timezone_set('Europe/London');
用戶可以選擇自己的時區,並在數據庫中保存爲4.0
(迪拜)
現在我想有這麼用戶選擇的時區對網站上存在的倒計時有影響。倒計時看起來是這樣的:
$today_date = new DateTime('now'); // now
$final_date = new DateTime($date); // a date in the future
$interval = $today_date->diff($final_date); // find the difference
$time_left = $interval->format('starting in %d days, %h hours and %i minutes'); // display it
在此之上,我做以下內容:
$userGMT = $user->get_gmt();
date_default_timezone_set($userGMT);
不工作正確的。歐洲/倫敦時區仍然倒計時,而不是我選擇的那個。
我試過做echo time('H:i:s');並可以看到上面已經受到影響的時間,它顯示了我選擇的時區的時間。
這樣的工作,但dateTime('現在');犯規?
你嘗試'新的日期時間( '現在',新DateTimeZone(「歐洲/倫敦))'? – 2012-04-17 22:45:50
是的,沒有爲我工作 – Karem 2012-04-18 07:07:25
你打開'error_reporting(E_ALL)'和'ini_set('display_errors','1')'來捕獲所有可能的錯誤(只在開發當然)?所有時區是否正確安裝?在控制檯中用'locale -a'檢查。 – 2012-04-18 07:12:24