Welcome, guest | Sign In | My Account | Store | Cart

This is a way to tell if your timezone is currently in daylight savings time. (Hint: time.daylight doesn't do this)

Python, 1 line
1
isdst = time.localtime()[-1] # localtime with no arg needs 2.1 or greater

I misunderstood time.daylight. Where I live (east coast USA), time.daylight is ALWAYS 1 (because this timezone has daylight savings time for part of the year)

1 comment

Andrew Smedley 14 years, 8 months ago  # | flag

Using the attribute name increases readability.

isdst = time.localtime().tm_isdst

Created by Doug Fort on Thu, 31 Oct 2002 (PSF)
Python recipes (4591)
Doug Fort's recipes (5)

Required Modules

  • (none specified)

Other Information and Tasks