开发者

Why is getdate(0) returning 1 as the hour?

开发者 https://www.devze.com 2023-03-14 14:07 出处:网络
I\'m using the getdate function, and I\'m i开发者_如何学JAVAntending to use it to parse a time interval, in seconds, into days, minutes, hours, etc. However, I\'m surprised that getdate(0)[\'hours\']

I'm using the getdate function, and I'm i开发者_如何学JAVAntending to use it to parse a time interval, in seconds, into days, minutes, hours, etc. However, I'm surprised that getdate(0)['hours'] is 1. What's going on here?

FWIW, the complete output I get is:

Array
(
    [seconds] => 0
    [minutes] => 0
    [hours] => 1
    [mday] => 1
    [wday] => 4
    [mon] => 1
    [year] => 1970
    [yday] => 0
    [weekday] => Thursday
    [month] => January
    [0] => 0
)


January 1, 1970, 00:00 GMT was 01:00 in BST (British Standard Time). Your server presumably has that time zone set.

See this Wolfram Alpha query.

Use date_default_timezone_set() to change the time zone, or use the new DateTime class that is completely timezone aware.


My guess would be that you are living in the UK.

PHP is configured to use the local timezone of your country. This results in a time of 1:00: GMT + 1 hour for the Daylight Savings.

There are 2 possible solutions:

  • Substract one hour from the timestamp you're using
  • Configure your script to use GMT. Use the function @pekka mentioned to do this.

I suggest the first solution; your script might need to pretty print individual times, along with the intervals, which you want to have converted to your local timezone.

0

精彩评论

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