Time zones `Etc/GMT`, why it is other way round?

后端 未结 1 1723
暗喜
暗喜 2021-01-07 05:06

Time zones in php work like this https://www.gsp.com/support/virtual/admin/unix/tz/gmt/

and when it named Etc/GMT+11 it actually GMT-11

相关标签:
1条回答
  • 2021-01-07 05:45

    This is not a bug. The tz database identifiers of the form Etc/GMT±* deliberately have an inverted sign than the usual forms we expect under ISO 8601. That is, they are in terms of positive values being West of GMT, rather than positive values being East of GMT.

    The reason is for backwards compatibility with POSIX style time zone identifiers, such as are used with the first format of the TZ environment variable. When POSIX compliant systems interpret this variable, values like America/Los_Angeles would clearly fall through to the third format (described in the same document), but values like Etc/GMT+11 are ambiguous as to which format rules should apply. Thus the zone identifiers must have their signs inverted to be compliant.

    From the tz database where these zones are defined:

    # Be consistent with POSIX TZ settings in the Zone names,
    # even though this is the opposite of what many people expect.
    # POSIX has positive signs west of Greenwich, but many people expect
    # positive signs east of Greenwich.  For example, TZ='Etc/GMT+4' uses
    # the abbreviation "-04" and corresponds to 4 hours behind UT
    # (i.e. west of Greenwich) even though many people would expect it to
    # mean 4 hours ahead of UT (i.e. east of Greenwich).
    

    This is also discussed in the Wikipedia article on the tz database.

    As far as practical matters, the tz database commentary also says:

    # These entries are mostly present for historical reasons, so that
    # people in areas not otherwise covered by the tz files could "zic -l"
    # to a time zone that was right for their area.  These days, the
    # tz files cover almost all the inhabited world, and the only practical
    # need now for the entries that are not on UTC are for ships at sea
    # that cannot use POSIX TZ settings.
    

    So, if you're not keeping time for ships at sea, I highly suggest you use a locality based identifier instead. (perhaps Australia/Melbourne ?)

    Also, A better source of time zone identifiers would be the one on Wikipedia.

    Since you said you were using PHP note that the PHP documentation has a list as well, and on the "Others" page, it actually explains this as well:

    Warning Please do not use any of the timezones listed here (besides UTC), they only exist for backward compatible reasons, and may expose erroneous behavior.

    Warning If you disregard the above warning, please also note that the IANA timezone database that provides PHP's timezone support uses POSIX style signs, which results in the Etc/GMT+n and Etc/GMT-n time zones being reversed from common usage.

    For example, the time zone 8 hours ahead of GMT that is used in China and Western Australia (among other places) is actually Etc/GMT-8 in this database, not Etc/GMT+8 as you would normally expect.

    Once again, it is strongly recommended that you use the correct time zone for your location, such as Asia/Shanghai or Australia/Perth for the above examples.

    0 讨论(0)
提交回复
热议问题