Skip to content

Instantly share code, notes, and snippets.

@snowsky
Forked from dpapathanasiou/dst.py
Created February 4, 2020 02:14
Show Gist options
  • Select an option

  • Save snowsky/ae0036cc195c85e6c60197bd1108cc5c to your computer and use it in GitHub Desktop.

Select an option

Save snowsky/ae0036cc195c85e6c60197bd1108cc5c 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