php date() 比服务器时间提前一小时(夏令时问题)
我正在尝试排查并解决这个问题: 我正在使用的服务器(Linux 上的 php 5.2.9)具有正确的本地时间(America/Buenos_Aires):
user@server [/home/site/public_html]$ date
Mon Nov 1 17:11:14 ART 2010
php.ini
设置为 date.timezone = "America/布宜诺斯艾利斯”
我还尝试直接在脚本中设置时区,
<?php
ini_set('display_errors', true);
error_reporting(E_ALL|E_STRICT|E_NOTICE);
//date_default_timezone_set("America/Buenos_Aires");
//echo date_default_timezone_get(), "<br>";
echo "ini: ", ini_get('date.timezone'), "<br>";
$now = date("H:i:s T I");
$nowdate = date("Y-m-d");
echo $nowdate." ".$now;
?>
但无济于事,结果是
ini: America/Buenos_Aires
2010-11-01 18:11:14 ARST 1
它应该显示 17:11
(始终提前一小时)。我在这里和网上找到的所有内容都指向
- date_default_timezone_set (我尝试过)
- 在 php.ini (已设置)中设置 date.timezone ,
- 混淆了服务器时间与客户端时间(我不是)。
有什么想法吗?
编辑: 按照建议,我检查了,正如您在代码中看到的那样,PHP 认为应该应用 DST,而阿根廷决定今年不应用它。除了等待补丁还有什么办法吗?
编辑2: 我尝试按照建议转储时区转换。我得到以下信息:
The timezone America/Buenos_Aires switches to standard time on 20 Mar 2011 @ 02:00.
The new GMT offset will be: -10800 (ART)
I'm trying to troubleshoot and solve this problem:
the server I'm working on (php 5.2.9 on Linux), has the correct local time (America/Buenos_Aires):
user@server [/home/site/public_html]$ date
Mon Nov 1 17:11:14 ART 2010
php.ini
is set with date.timezone = "America/Buenos_Aires"
I also tried to set the timezone directly in the script with
<?php
ini_set('display_errors', true);
error_reporting(E_ALL|E_STRICT|E_NOTICE);
//date_default_timezone_set("America/Buenos_Aires");
//echo date_default_timezone_get(), "<br>";
echo "ini: ", ini_get('date.timezone'), "<br>";
$now = date("H:i:s T I");
$nowdate = date("Y-m-d");
echo $nowdate." ".$now;
?>
but to no avail, the result is
ini: America/Buenos_Aires
2010-11-01 18:11:14 ARST 1
when it should read 17:11
(It's consistently one hour ahead). All I've found here and on the web pointed to
- date_default_timezone_set (which I tried)
- setting date.timezone in php.ini (which it is set)
- confusing server time with client time (which I'm not).
Any ideas?
EDIT:
As suggested, I checked and as you can see in the code, PHP thinks it should be applying DST, and Argentina decided to not apply it this year. Any option besides waiting for a patch?
EDIT 2:
I tried dumping the timezones transition as suggested. I got the following:
The timezone America/Buenos_Aires switches to standard time on 20 Mar 2011 @ 02:00.
The new GMT offset will be: -10800 (ART)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几天前有一个问题表明 PHP 还没有收到消息事实上,阿根廷今年才取消夏令时。看来这个决定还没有进入代码库。 (但尚未得到证实,因此不能 100% 清楚是否是这样。)
也许尝试 以同样的方式转储您的时区,看看这是否也适用于您的 PHP 版本。
更新:这似乎确实是问题所在。我能想到的最好的解决方案是使用时区的偏移量,例如
Etc/GMT-3
有人应该向 bugs.php.net 提交一个错误,但似乎没有这样的错误。
There was a question a few days back that suggested that PHP hasn't yet got wind of the fact that Argentina got rid of DST only this year. It seems like this decision hasn't made it into the code base yet. (But it was not confirmed, so it's not 100% clear whether this was it.)
Maybe try dumping your time zones the same way to see whether that applies to your PHP version, too.
Update: This indeed seems to be the problem. The best solution I can think of is to use an offset in the time zone, e.g.
Etc/GMT-3
Somebody should file a bug with bugs.php.net, there doesn't seem to be one for this.