我不明白,爲什麼下面的代碼減去UNIX紀元時間戳的一個小時(在時區UTC + 1):時區處理對象
import datetime
import pytz
start_dt = datetime.datetime.fromtimestamp(1362268800 , pytz.utc)
print start_dt
# prints datetime.datetime(2013, 3, 3, 0, 0, tzinfo=<UTC>)
print int(start_dt.strftime("%s"))
# prints: 1362265200 (which is 2013-03-02T23:00Z) <--- I expected 1362268800
print start_dt.strftime("%Y-%m-%dT%H:%M:%SZ")
# prints: 2013-03-03T00:00:00Z
因爲我已經在我的問題,通過砍死使用calendar.timegm(start_ts.timetuple())
,但我從根本上想知道上面的代碼有什麼問題,以及如何創建UTC格式的日期時間對象,以及strftime將打印曆元時間戳的位置。
根據python文檔使用「%s」不是特別允許的。是否應該明確地不允許(即引發異常?)如果它導致混淆結果?
使用Python 2.7.3
[將日期,日期時間對象轉換爲POSIX時間戳的各種方法](http://stackoverflow.com/a/8778548/4279) – jfs 2013-03-13 09:26:59