我的服務器是Central Time,我正在嘗試顯示尼日利亞Abuja(顯示其時間)的事件。顯示正確的時區PHP date_default_timezone_set()導致非洲/拉各斯的時間不正確
我的PHP代碼如下...
// since our server is central time we have to make the server think it's in a different time zone or it will display all times using the central offset
// date_default_timezone_set("bleh") is used to do this
// php supported time zones (http://us3.php.net/manual/en/timezones.php)
// you have to specify every time zone (even odd-balls like Napal) if you want every time zone to work correctly
if ($pubDatetimezone == "PST" || $pubDatetimezone == "PDT") date_default_timezone_set("America/Los_Angeles");
if ($pubDatetimezone == "MST" || $pubDatetimezone == "MDT") date_default_timezone_set("America/Denver");
if ($pubDatetimezone == "CST" || $pubDatetimezone == "CDT") date_default_timezone_set("America/Chicago");
if ($pubDatetimezone == "EST" || $pubDatetimezone == "EDT") date_default_timezone_set("America/Montreal");
// shows the incorrect time but the correct time zone (WAT)
if ($pubDatetimezone == "WAT") date_default_timezone_set("Africa/Lagos");
// displays the correct time but the incorrect time zone (AZOT)
// if ($pubDatetimezone == "WAT") date_default_timezone_set("Atlantic/Azores");
美國時區工作得很好,但非洲時區顯示不正確。日期/時間應該顯示Friday, November 01, 2013 @ 6:00pm WAT
,但它顯示Friday, November 01, 2013 @ 8:00pm WAT
。
我的服務器時間是正確的(在正確時間和正確時區的幾分鐘內)。我正在導入的XML數據具有正確的日期/時間<pubDate>Fri, 01 Nov 2013 18:00:00 WAT</pubDate>
。值得注意的是,我使用的是Windows服務器,IIS 7和PHP 5.3.10。
WAT不使用夏令時。即使這樣做了,那麼時間只會是1個小時,而且是2個小時。我們最終必須在XML中放入不正確的時間,以便PHP顯示正確的時間。
有什麼不對?
您是否嘗試過更新時區數據庫? (http://pecl.php.net/package/timezonedb) – ernie