开发者

Why php timestamp behave like this? 03/November/1985

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 wher开发者_如何转开发e 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜