-
-
Save jonatasnona/8c4aac63919db9718cd663de2a8b6d80 to your computer and use it in GitHub Desktop.
How to tell if Daylight Savings Time is in effect using Python
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
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