为什么 php 时间戳会这样? 1985 年 11 月 03 日
我试图使用我的默认时区 *(America/Sao_Paulo)* 制作自己的 php mktime();
。 它工作正常,但我注意到有些时间戳比应有的时间多了一小时。 所以我追踪并找出了脚本开始丢失的日期:03/November/1985 我进行了一些测试,由于一些奇怪的原因(这就是我想要理解的),这一天只有 23 个小时! 检查一下:
<?php
date_default_timezone_set('America/Sao_Paulo');
//shows 23
echo (mktime(0,0,0,11,03,1985)- mktime(0,0,0,11,02,1985))/3600;
//any other date, shows 24
echo '<br/>'.(mktime(0,0,0,11,3,2000)-mktime(0,0,0,11,2,2000))/3600;
?>
请注意,时区 UTC 不会出现这种情况。 这可能是一个错误吗?
PS:抱歉英语错误。
I was trying to make my own php mktime();
using my default timezone *(America/Sao_Paulo)*.
It was working ok, but I noticed that some timestamps had one hour more than it should be.
So I tracked down and find out this date where the script starts to miss: 03/November/1985
I ran some tests and for some weird reason (that's what I'm trying to understand), this day have only 23 hours!
Check it:
<?php
date_default_timezone_set('America/Sao_Paulo');
//shows 23
echo (mktime(0,0,0,11,03,1985)- mktime(0,0,0,11,02,1985))/3600;
//any other date, shows 24
echo '<br/>'.(mktime(0,0,0,11,3,2000)-mktime(0,0,0,11,2,2000))/3600;
?>
Notice that it doesn't occurs with timezone UTC.
It's a possible bug?
PS: Sorry for english mistakes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您碰巧选择了代表 1985 年巴西夏令时开始的日期。请参阅 http: //tldp.org/HOWTO/TimePrecision-HOWTO/tz.html。
因此,由于该特定日期的时间变化,这两天的午夜之间的时差仅为 23 小时。
You happened to pick the date that represents the start of daylight savings in Brazil for 1985. See http://tldp.org/HOWTO/TimePrecision-HOWTO/tz.html.
So, because of the time change on that specific date, the difference between midnight on the two days is only 23 hours.
听起来像是夏令时问题。可能只有 23 小时,因为夏令时将时钟提前,跳过了 1 小时。
mktime 有一个额外的参数,名为
is_dst
。尝试将其设置为 0 或 1,看看是否可以解决您的问题,尽管您得到的输出很可能是正确的。Sounds like a day light savings time issue. Probably only has 23 hours because DST pushes the clock ahead, skipping 1 hour.
There's an extra argument to mktime called
is_dst
. Try setting it to 0 or 1 and see if that fixes your problem, although the output you're getting might very well be correct.