我無法理解pytz中「Etc/GMT-5」時區和UTC之間的轉換。pytz and Etc/GMT-5
>>> 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錯誤嗎?
你擊敗了我自己的答案23秒! :) – 2010-10-24 16:28:12