Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pytz DST的问题_Python_Timezone Offset_Pytz - Fatal编程技术网

Python pytz DST的问题

Python pytz DST的问题,python,timezone-offset,pytz,Python,Timezone Offset,Pytz,我试图理解pytz是如何处理DST的,下面是一个来自的示例,其中相关部分如下: >>> fmt = '%Y-%m-%d %H:%M:%S %Z%z' >>> eastern = timezone('US/Eastern') >>> loc_dt = datetime(2002, 10, 27, 1, 30, 00) >>> est_dt = eastern.localize(loc_dt, is_dst=True) >

我试图理解pytz是如何处理DST的,下面是一个来自的示例,其中相关部分如下:

>>> fmt = '%Y-%m-%d %H:%M:%S %Z%z'
>>> eastern = timezone('US/Eastern')
>>> loc_dt = datetime(2002, 10, 27, 1, 30, 00)
>>> est_dt = eastern.localize(loc_dt, is_dst=True)
>>> edt_dt = eastern.localize(loc_dt, is_dst=False)
>>> print(est_dt.strftime(fmt) + ' / ' + edt_dt.strftime(fmt))
2002-10-27 01:30:00 EDT-0400 / 2002-10-27 01:30:00 EST-0500
有趣的是,使用
year=2020
重复该示例会产生两个偏移量为-0400的EDT日期:

>>> loc_dt = datetime(2020, 10, 27, 1, 30, 00)
>>> est_dt = eastern.localize(loc_dt, is_dst=True)
>>> edt_dt = eastern.localize(loc_dt, is_dst=False)
>>> print(est_dt.strftime(fmt) + ' / ' + edt_dt.strftime(fmt))
2020-10-27 01:30:00 EDT-0400 / 2020-10-27 01:30:00 EDT-0400

为什么没有偏移量为-0500的EST日期?

2002年10月27日是夏令时过渡日。2020年的过渡日为2020年11月1日。我认为
只会影响过渡时间内的时间,否则会被忽略。@MarkRansom:我现在明白了。非常感谢。