Created
April 25, 2018 20:34
-
-
Save loisaidasam/db16c8ddfcd1c39fca66ff87bee16383 to your computer and use it in GitHub Desktop.
Python: Eastern Standard Time vs. Eastern Daylight Time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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