-
-
Save snowsky/ae0036cc195c85e6c60197bd1108cc5c to your computer and use it in GitHub Desktop.
How to tell if Daylight Savings Time is in effect using Python
This file contains hidden or 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
| from datetime import datetime | |
| import pytz | |
| def is_dst (): | |
| """Determine whether or not Daylight Savings Time (DST) | |
| is currently in effect""" | |
| x = datetime(datetime.now().year, 1, 1, 0, 0, 0, tzinfo=pytz.timezone('US/Eastern')) # Jan 1 of this year | |
| y = datetime.now(pytz.timezone('US/Eastern')) | |
| # if DST is in effect, their offsets will be different | |
| return not (y.utcoffset() == x.utcoffset()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment