Search code examples
pythondatetimetimetimezonedst

python time module: daylight savings


I have a question about python's time module specifically (not asking about datetime, pytz, or any other module).

How can I find out, using the time module, whether it is currently daylight savings time (DST) in the place and date where I currently am?

The documentation seems vague on this topic. I would have thought that time.daylight would be 0 if it's currently standard time (winter) vs nonzero if it's currently daylight time (summer), based on my interpretation of how the docstring is worded: Nonzero if a DST timezone is defined.

However, it seems that this is not what time.daylight does! Currently it is winter (standard) time here, but time.daylight == 1

How can I use the time module to find out if it is currently DST? Or is this impossible? Thanks!


Solution

  • How can I find out, using the time module, whether it is currently daylight savings time (DST) in the place and date where I currently am?

    Assuming your computer is set to the correct timezone:

    import time
    
    is_dst = time.daylight and time.localtime().tm_isdst > 0