简体   繁体   English

PHP date_default_timezone_set()导致非洲/拉各斯的时间不正确

[英]PHP date_default_timezone_set() Resulting In Incorrect Time For Africa/Lagos

My server is Central Time and I'm trying to display an event for Abuja, Nigeria (displaying in their time). 我的服务器是中部时间,我正在尝试显示尼日利亚阿布贾的事件(以他们的时间显示)。

My PHP code for displaying the correct time zones is as follows... 我的用于显示正确时区的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");

The American time zones work just fine, but the African time zone is displaying incorrectly. 美国时区工作正常,但非洲时区显示不正确。 The date/time should show Friday, November 01, 2013 @ 6:00pm WAT but it is showing Friday, November 01, 2013 @ 8:00pm WAT . 日期/时间应显示为Friday, November 01, 2013 @ 6:00pm WAT但显示为Friday, November 01, 2013 @ 8:00pm WAT

My server time is decently correct (within a few minutes of the correct time and the correct time zone). 我的服务器时间是正确的(在正确时间和正确时区的几分钟内)。 The XML data that I'm importing has the correct date/time <pubDate>Fri, 01 Nov 2013 18:00:00 WAT</pubDate> . 我正在导入的XML数据具有正确的日期/时间<pubDate>Fri, 01 Nov 2013 18:00:00 WAT</pubDate> It could be worth noting that I'm using a Windows server, IIS 7, and PHP 5.3.10. 可能值得注意的是,我使用的是Windows服务器,IIS 7和PHP 5.3.10。

WAT doesn't use daylight saving time. WAT不使用夏令时。 Even if it did, then the time would only be 1 hour off and it's 2 hours off. 即使这样做了,时间也只不过是1个小时,而是2个小时。 We ended up having to put incorrect times in our XML so that PHP would display correct times. 我们最终不得不在XML中放入错误的时间,这样PHP才能显示正确的时间。

Any ideas as to what's wrong? 有什么问题的想法吗?

The timezones database in PHP got deprecated. PHP中的时区数据库已弃用。 The best thing you can do is upgrade PHP to the latest 5.3. 最好的办法是将PHP升级到最新的5.3。 Apart from up-to-date timezones you'll get all the latest security fixes - the version 5.3.10 is pretty old and there were quite a few security issues fixed. 除了最新的时区之外,您还将获得所有最新的安全修复程序-版本5.3.10相当老,并且修复了很多安全问题。

Unfortunately it's impossible to update only timezones db in PHP on Windows, as it's compiled into the binary files. 不幸的是,由于Windows已将其编译为二进制文件,因此无法仅在Windows上的PHP中更新时区db。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM