如果我將UTC日期時間轉換爲瑞典格式,則包含夏令時(CEST)。但是,在使用瑞典作爲時區創建日期時,它將獲得CET而不是CEST。爲什麼是這樣?使用pytz時區時不包括DST的Python日期時間
>>> # Modified for readability
>>> import pytz
>>> import datetime
>>> sweden = pytz.timezone('Europe/Stockholm')
>>>
>>> datetime.datetime(2010, 4, 20, 16, 20, tzinfo=pytz.utc).astimezone(sweden)
datetime(2010, 4, 20, 18, 20, tzinfo=<... 'Europe/Stockholm' CEST+2:00:00 DST>)
>>>
>>> datetime.datetime(2010, 4, 20, 18, 20, tzinfo=sweden)
datetime(2010, 4, 20, 18, 20, tzinfo=<... 'Europe/Stockholm' CET+1:00:00 STD>)
>>>
感謝您的信息!此外,pytz.timezone對象的本地化函數可用於構建本地化日期時間,而不是日期時間(...,tzinfo =) –
Jesper
2010-04-17 23:42:33
@Jesper:[pytz docs](http://pytz.sf.net )明確地說,使用.localize()而不是使用datetime構造函數的tzinfo參數用於帶DST的時區。 – jfs 2012-12-12 16:20:59