我很难理解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:
^{pr2}$所以在我看来,从GMT-5的10:00转换到UTC时,我得到的是05:00?我希望派兹给我15点的时间。在
我错过了什么?在
编辑:我已经确认美国/东部时区的时区转换与我预期的一样:
>>> 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得到的。这是皮兹虫吗?在
这显然是POSIX的事情。来自Wikipedia:
This bug report解释此行为。显然,他们知道这一切都是颠倒的,但那是因为任何其他东西都会破坏兼容性。在
相关问题 更多 >
编程相关推荐