Skip to content

Instantly share code, notes, and snippets.

@jonatasnona
Forked from dpapathanasiou/dst.py
Created November 4, 2018 11:56
Show Gist options
  • Save jonatasnona/8c4aac63919db9718cd663de2a8b6d80 to your computer and use it in GitHub Desktop.
Save jonatasnona/8c4aac63919db9718cd663de2a8b6d80 to your computer and use it in GitHub Desktop.
How to tell if Daylight Savings Time is in effect using Python
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