python – pytz和Etc / GMT-5

我无法理解pytz中“Etc / GMT-5”时区和UTC之间的转换.

>>> dt = datetime(2009, 9, 9, 10, 0) # September 9 2009, 10:00
>>> gmt_5 = pytz.timezone("Etc/GMT-5")
>>> gmt_5.localize(dt)
datetime.datetime(2009, 9, 9, 10, 0, tzinfo=<StaticTzInfo 'Etc/GMT-5'>)

到目前为止一切都很好,但后来我尝试将其转换为UTC:

>>> gmt_5.localize(dt).astimezone(pytz.utc)
datetime.datetime(2009, 9, 9, 5, 0, tzinfo=<UTC>)

所以对我来说,似乎从GMT-5的10:00转换到UTC我得到05:00?我希望pytz给我15:00代替.

我错过了什么?

编辑:我已经确认美国/东部时区的时区转换正如我所期望的那样:

>>> eastern = pytz.timezone("US/Eastern")
>>> eastern.localize(dt)
datetime.datetime(2009, 9, 9, 10, 0, tzinfo=...) # Too long
>>> pytz.utc.normalize(eastern.localize(dt).astimezone(pytz.utc))
datetime.datetime(2009, 9, 9, 14, 0, tzinfo=<UTC>)

编辑2:我已经确认,当我使用Etc / GMT 5时,我得到15:00,这是我期望从Etc / GMT-5获得的.这是一个pytz bug吗?

这显然是POSIX的事情.从Wikipedia开始:

In order to conform with the POSIX style, those zones beginning with “Etc/GMT” have their sign reversed from what most people expect. In this style, zones west of GMT have a positive sign and those east have a negative sign.

https://stackoverflow.com/questions/4008960/pytz-and-etc-gmt-5

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:python – pytz和Etc / GMT-5