Skip to content

Instantly share code, notes, and snippets.

@loisaidasam
Created April 25, 2018 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loisaidasam/db16c8ddfcd1c39fca66ff87bee16383 to your computer and use it in GitHub Desktop.
Save loisaidasam/db16c8ddfcd1c39fca66ff87bee16383 to your computer and use it in GitHub Desktop.
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