带有DST的Python pytz问题

带有DST的Python pytz问题,python,datetime,timezone,pytz,Python,Datetime,Timezone,Pytz,我正在使用命令 datetime.datetime.fromtimestamp(int(1364691600)).replace(tzinfo=pytz.utc).astimezone(pytz.timezone("Europe/London")) 这是回报 datetime.datetime(2013, 3, 31, 3, 0, tzinfo=<DstTzInfo 'Europe/London' BST+1:00:00 DST>) datetime.datetime(2013,

我正在使用命令

datetime.datetime.fromtimestamp(int(1364691600)).replace(tzinfo=pytz.utc).astimezone(pytz.timezone("Europe/London"))
这是回报

datetime.datetime(2013, 3, 31, 3, 0, tzinfo=<DstTzInfo 'Europe/London' BST+1:00:00 DST>)
datetime.datetime(2013,3,31,3,0,tzinfo=)
这肯定会回来

datetime.datetime(2013, 3, 31, 2, 0, tzinfo=<DstTzInfo 'Europe/London' BST+1:00:00 DST>)
datetime.datetime(2013,3,31,2,0,tzinfo=)
我认为这是因为当BST切换时是1小时,而在这里是2小时

>>> datetime.datetime.fromtimestamp(int(1364691599)).replace(tzinfo=pytz.utc).astimezone(pytz.timezone("Europe/London"))
datetime.datetime(2013, 3, 31, 0, 59, 59, tzinfo=<DstTzInfo 'Europe/London' GMT0:00:00 STD>)
>>datetime.datetime.fromtimestamp(int(1364691599)).replace(tzinfo=pytz.utc).astimezone(pytz.timezone(“欧洲/伦敦”))
datetime.datetime(2013,3,31,0,59,59,tzinfo=)
fromtimestamp(tz=None)
使用您的本地时区,并且您的本地时区不是utc,因此对结果调用
。replace(tzinf=pytz.utc)

而是直接传递时区:

>>>> from datetime import datetime 
>>> import pytz # $ pip install pytz
>>> datetime.fromtimestamp(1364691600, pytz.timezone("Europe/London"))
datetime.datetime(2013, 3, 31, 2, 0, tzinfo=<DstTzInfo 'Europe/London' BST+1:00:00 DST>)
>>>>从日期时间导入日期时间
>>>导入pytz#$pip安装pytz
>>>datetime.fromtimestamp(1364691600,pytz.时区(“欧洲/伦敦”))
datetime.datetime(2013,3,31,2,0,tzinfo=)