Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python time.time() and "Daylight Saving Time"

What happens when the clock of the computer running python (Windows or Linux) gets automatically changed and a call time.time()?

I've read that the value of time.time() will be smaller when the clock is changed manually to some value in the past.

like image 894
David Stark Avatar asked Sep 09 '15 00:09

David Stark


People also ask

How does Python handle Daylight Savings Time?

You can use time. localtime and look at the tm_isdst flag in the return value. Using time. localtime() , you can ask the same question for any arbitrary time to see whether DST would be (or was) in effect for your current time zone.

How do you check is daylight saving is on in Python?

daylight() Function. Time. daylight() function which returns a non zero integer value when Daylight Saving Time (DST) is defined, else it returns 0.

Does pytz handle DST?

pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher. It also solves the issue of ambiguous times at the end of daylight saving time, which you can read more about in the Python Library Reference ( datetime. tzinfo ).

What is the function to offset the date for daylight saving in time series?

IsDaylightSavingTime(DateTimeOffset) Indicates whether a specified date and time falls in the range of daylight saving time for the time zone of the current TimeZoneInfo object.


1 Answers

time.time() docs state:

Return the time in seconds since the epoch as a floating point number.

The particular epoch referred to here is the Unix epoch, which is Midnight, Jan 1st 1970 UTC.

Since it is always based on UTC, it will not be affected by changing the computer's time zone, nor when the computer's time zone enters or exits daylight saving time.

Though the function does rely on the underlying implementation to provide the value, those implementations always return values in terms of UTC - regardless of operating system.

On Windows in particular, it ultimately calls the GetSystemTimeAsFileTime OS function, which returns its value in terms of UTC. It is not affected by time zone selection or by DST changes within the time zone.

like image 124
Matt Johnson-Pint Avatar answered Sep 23 '22 19:09

Matt Johnson-Pint