时区`Etc/GMT`,为什么是相反的?
Time zones `Etc/GMT`, why it is other way round?
php 中的时区是这样工作的 https://www.gsp.com/support/virtual/admin/unix/tz/gmt/
当它命名为 Etc/GMT+11
时,它实际上是 GMT-11
当它命名为 Etc/GMT-11
时,它实际上是 GMT+11
为什么? Etc/GMT
是什么意思?
我在 PHP 中找到它,它是 PHP 中的错误还是到处都是?
这不是错误。 Etc/GMT±*
形式的 tz 数据库标识符故意有一个倒符号,而不是我们在 ISO 8601 下期望的通常形式。也就是说,它们是正值是格林威治标准时间以西,而不是正值是格林威治标准时间以东.
原因是为了向后兼容 POSIX 样式的时区标识符,例如用于 the TZ
environment variable 的第一种格式。当 POSIX 兼容系统解释此变量时,像 America/Los_Angeles
这样的值显然会落入第三种格式(在同一文档中描述),但是像 Etc/GMT+11
这样的值对于格式规则是不明确的应该适用。因此,区域标识符必须将其符号反转才能符合要求。
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).
这也在the Wikipedia article on the tz database中讨论。
就实际问题而言,tz数据库评论也说:
# 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.
因此,如果您不为海上船只计时,我强烈建议您改用基于位置的标识符。 (也许 Australia/Melbourne
?)
此外,更好的时区标识符来源是 the one on Wikipedia。
既然你说你在使用 PHP 请注意 the PHP documentation has a list as well, and on the "Others" 页面,它实际上也解释了这一点:
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.
php 中的时区是这样工作的 https://www.gsp.com/support/virtual/admin/unix/tz/gmt/
当它命名为 Etc/GMT+11
时,它实际上是 GMT-11
当它命名为 Etc/GMT-11
时,它实际上是 GMT+11
为什么? Etc/GMT
是什么意思?
我在 PHP 中找到它,它是 PHP 中的错误还是到处都是?
这不是错误。 Etc/GMT±*
形式的 tz 数据库标识符故意有一个倒符号,而不是我们在 ISO 8601 下期望的通常形式。也就是说,它们是正值是格林威治标准时间以西,而不是正值是格林威治标准时间以东.
原因是为了向后兼容 POSIX 样式的时区标识符,例如用于 the TZ
environment variable 的第一种格式。当 POSIX 兼容系统解释此变量时,像 America/Los_Angeles
这样的值显然会落入第三种格式(在同一文档中描述),但是像 Etc/GMT+11
这样的值对于格式规则是不明确的应该适用。因此,区域标识符必须将其符号反转才能符合要求。
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).
这也在the Wikipedia article on the tz database中讨论。
就实际问题而言,tz数据库评论也说:
# 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.
因此,如果您不为海上船只计时,我强烈建议您改用基于位置的标识符。 (也许 Australia/Melbourne
?)
此外,更好的时区标识符来源是 the one on Wikipedia。
既然你说你在使用 PHP 请注意 the PHP documentation has a list as well, and on the "Others" 页面,它实际上也解释了这一点:
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.