Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python: Eastern Standard Time vs. Eastern Daylight Time
"""
https://en.wikipedia.org/wiki/Eastern_Time_Zone
"""
>>> 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.