澳大利亚DST时区缩写使用date_default_timezone_set时不正确 [英] Australia DST timezone abbreviation incorrect when using date_default_timezone_set

查看:137
本文介绍了澳大利亚DST时区缩写使用date_default_timezone_set时不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP的date_default_timezone_set函数来表示不同时区的UTC时间戳。夏令时刚刚在这里(NZ)和澳大利亚踢了,我正在获得混合的结果...

I'm trying to represent a UTC timestamp in different timezones using PHP's date_default_timezone_set function. Daylight saving has just kicked in here (NZ) and in Australia, and I'm getting mixed results...

这里有一些测试代码...

Here's some test code...

date_default_timezone_set('NZ');
print '<p>NZ time is ' . date('Y-m-d H:i:s T (I)') . '</p>';

date_default_timezone_set('Australia/NSW');
print '<p>NSW time is ' . date('Y-m-d H:i:s T (I)') . '</p>';

date_default_timezone_set('Australia/North');
print '<p>NT time is ' . date('Y-m-d H:i:s T (I)') . '</p>';

date_default_timezone_set('Australia/South');
print '<p>SA time is ' . date('Y-m-d H:i:s T (I)') . '</p>';

从中我得到这个输出...

From which I get this output...

NZ time is 2014-10-05 14:04:27 NZDT (1)

NSW time is 2014-10-05 12:04:27 EST (1)

NT time is 2014-10-05 10:34:27 CST (0)

SA time is 2014-10-05 11:34:27 CST (1)

现在,NZ时区缩写是正确的(NZDT),所有的澳大利亚 times 是正确的,但是澳大利亚的两个夏令时间是活跃的(如日期为'I'格式的字符,如果夏令时有效,则返回'1')仍然显示非DST缩写。

Now, the NZ timezone abbreviation is correct (NZDT), and all the Australian times are correct, but the two Australian times where daylight saving is active (as indicated by the php date 'I' format character, which returns a '1' if daylight savings is in place) are still showing the non-DST abbreviation.

任何想法?

推荐答案

几件事:


  • 只要有可能,您应该更喜欢时区名称的规范形式。您提到的区域实际上是链接(aka 别名)。有关详细信息,请参见此图表。具体来说:

  • You should prefer the canonical form of the time zone name whenever possible. The zones you mentioned are actually links (aka aliases). Refer to this chart for details. Specifically:

NZ              => Pacific/Auckland
Australia/NSW   => Australia/Sydney
Australia/North => Australia/Darwin
Australia/South => Australia/Adelaide


  • 澳大利亚实际上有5个主要地区有不同的时区规则。有关详细信息,请参考本维基百科文章

    澳大利亚/达尔文(aka,澳大利亚/北部)没有观察到夏令时时间。

    Australia/Darwin (aka, Australia/North) does not observe daylight saving time at all.

    另外两个时区(悉尼和阿德莱德)确实在您指定的日期和时间的夏时制。然而,澳大利亚时区的名称和缩写并不完全清楚。例如,悉尼的日光名称已被以下所有参考:

    The other two time zones (Sydney & Adelaide) would indeed be on daylight saving time at the date and time you specified. However, names and abbreviations for Australian time zones have not necessarily been absolutely clear. For example, Sydney's daylight name has been referred to by all of the following:


    • 东部夏季时间(EST)

    • 澳大利亚东部夏令时间(AEST)

    • 东部夏令时间(EDT)

    • 澳大利亚东部夏令时间(AEDT)


    • Eastern Summer Time (EST)
    • Australian Eastern Summer Time (AEST)
    • Eastern Daylight Time (EDT)
    • Australian Eastern Daylight Time (AEDT)

    PHP将其时区从 IANA时区数据库。时区缩写也取自同一来源。很长一段时间,这个数据集在东部时间和东部夏令时间都使用了EST的含糊的缩写。

    PHP pulls its time zones from the IANA time zone database. Time zone abbreviations are also taken from the same source. For a very long time, this data set used the ambiguous abbreviation of "EST" for both Eastern Standard Time and Eastern Summer Time.

    这是最近更改版本2014f 。您可以在发行说明中阅读详细信息。现在使用AEST进行标准时间,AEDT用于日光时间。

    This was changed recently, in version 2014f. You can read the details in the release notes. It now uses AEST for standard time, and AEDT for daylight time.

    您可以通过更新PHP的 timezonedb 到2014.6版或更高版本。您可以在此处 here

    You can get this change by updating PHP's timezonedb to version 2014.6 or greater. You can find instructions for updating here or here.

    或者,你可以只需更新到最新版本的PHP 。根据发布日期,我认为 PHP版本5.3.29应该随着timezonedb 2014.6发货。使用该版本或更新版本,您应该获得新的缩写。

    Alternatively, you can just update to the latest version of PHP. Based on the release dates, I think PHP version 5.3.29 should have shipped with timezonedb 2014.6. Use that version or newer and you should get the new abbreviations.

    您还可以调用 timezone_version_get() 来查看你有什么版本的timezonedb。应该是2014.6或更高的收到新的缩写。

    You can also call timezone_version_get() to see what version of timezonedb you have. It should be 2014.6 or greater to receive the new abbreviations.

    这篇关于澳大利亚DST时区缩写使用date_default_timezone_set时不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆