doumiao0498 2013-07-26 03:26
浏览 56
已采纳

从PHP时区转换_get()返回的这个奇怪的值是什么?

I noticed something odd while using PHP's timezone_transitions_get(). The first element of the returned array seems to be this improbable/unuseable value, regardless of the timezone used:

php -r 'print_r(timezone_transitions_get(new DateTimeZone("GMT")));'
Array
(
    [0] => Array
        (
            [ts] => -9223372036854775808
            [time] => -292277022657-01-27T08:29:52+0000
            [offset] => 0
            [isdst] => 
            [abbr] => UTC
        )

)

php -r 'print_r(timezone_transitions_get(new DateTimeZone("US/Pacific")));'
Array
(
    [0] => Array
        (
            [ts] => -9223372036854775808
            [time] => -292277022657-01-27T08:29:52+0000
            [offset] => -25200
            [isdst] => 1
            [abbr] => PDT
        )
...

I've tried this with PHP 5.3 and 5.4. It seems to be independent of the version of PECL timezonedb used as well. Anyone know why this is happening?

  • 写回答

1条回答 默认 最新

  • doutizhou5312 2013-07-26 20:41
    关注

    Have a look at this documentation for reference of timezone_transitions_get. Apparently, they are missing the following details:

    The [ts] value represents the timestamp of the transition, as the number of microseconds since Midnight Jan 1 1970 UTC. It is stored as a 64-bit signed integer, which -9223372036854775808 is the smallest possible value.

    The [time] value is the ISO8601 string equivalent of the [ts] value. It looks funny for negative years, especially ones with that many digits, but that is indeed the mathematical equivalent.

    Think of these as the "beginning of time". Well, at least as far as computers are concerned. :-)

    The [offset] value is the number of whole seconds represented by the UTC offset of the transition. Divide by 3600 and you will get an equivalent number of hours.

    The [isdst] value is a boolean (1 or blank) indicating if the offset represents Daylight Saving Time.

    The [abbr] value is a short abbreviation describing the time zone. Abbreviations can be ambiguous, so it's just there as a display value and for easy reference. Nothing should be keyed off of it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗