[英]PHP date_default_timezone_set() Resulting In Incorrect Time For Africa/Lagos
我的服务器是中部时间,我正在尝试显示尼日利亚阿布贾的事件(以他们的时间显示)。
我的用于显示正确时区的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才能显示正确的时间。
有什么问题的想法吗?
PHP中的时区数据库已弃用。 最好的办法是将PHP升级到最新的5.3。 除了最新的时区之外,您还将获得所有最新的安全修复程序-版本5.3.10相当老,并且修复了很多安全问题。
不幸的是,由于Windows已将其编译为二进制文件,因此无法仅在Windows上的PHP中更新时区db。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.