Python - 根据一年中的时间将小时从EDT / EST转换为UTC

时间:2018-04-25 20:37:19

标签: python datetime timezone-offset

东部标准时间是-5(到UTC)

东部夏令时为-4(至UTC)

那么为什么这不能正常工作?

>>> import datetime, pytz

# 5 hour difference during Eastern Standard Time
>>> datetime.datetime(2018, 1, 25, 16, 26, tzinfo=pytz.timezone('US/Eastern')).hour
>>> 16

>>> datetime.datetime(2018, 1, 25, 16, 26, tzinfo=pytz.timezone('US/Eastern')).astimezone(pytz.utc).hour
>>> 21

# 4 hour difference during Eastern Daylight Time
>>> datetime.datetime(2018, 4, 25, 16, 26, tzinfo=pytz.timezone('US/Eastern')).hour
>>> 16

# So why does this not say 20?
>>> datetime.datetime(2018, 4, 25, 16, 26, tzinfo=pytz.timezone('US/Eastern')).astimezone(pytz.utc).hour
>>> 21

0 个答案:

没有答案