Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why python time has 61 seconds

Tags:

python

Did anybody notice that the interval of second in Python datetime is [00,61] see the table on this page. https://docs.python.org/3/library/time.html#time.strftime

Why?

like image 730
storm Avatar asked Feb 16 '12 06:02

storm


People also ask

What does Time Time () do in Python?

time() The time() function returns the number of seconds passed since epoch. For Unix system, January 1, 1970, 00:00:00 at UTC is epoch (the point where time begins).

How do you add 1 second to time in python?

Use the timedelta() class from the datetime module to add seconds to datetime, e.g. result = dt + timedelta(seconds=24) .

How do I print time in seconds in Python?

Use the time. time() function to get the current time in seconds since the epoch as a floating-point number. This method returns the current timestamp in a floating-point number that represents the number of seconds since Jan 1, 1970, 00:00:00. It returns the current time in seconds.


2 Answers

The answer is on the same page in footnote (2):

The range really is 0 to 61; value 60 is valid in timestamps representing leap seconds and value 61 is supported for historical reasons.

The "historical reasons" are described in https://bugs.python.org/issue2568.

like image 149
Eric O Lebigot Avatar answered Oct 06 '22 00:10

Eric O Lebigot


There is no such thing as a double leap second. There cannot be 62 seconds in a minute. 59, yes. 60, yes. 61, yes. 62, no.

http://www.monkey.org/openbsd/archive2/tech/199905/msg00031.html

like image 28
Greg Hennessy Avatar answered Oct 05 '22 23:10

Greg Hennessy