Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
452 views
in Technique[技术] by (71.8m points)

python - How many seconds elapsed since 01/01/1970, leap-seconds included?

The Unix timestamp given by:

int(time.time())

gives the number of seconds elapsed since 01/01/1970, without leap-seconds.

Just out of curiosity, how to get the true number of seconds elapsed since this date, leap-seconds included? (i.e. the distance between these two events on a time axis)

Notes:

  • Example: the timestamp range 867715190.000 .. 867715202.000 represents a "real-life duration" of 13 seconds (measured with a timer) because there was a leap-second this day of 1997, whereas the Unix timestamp has only increased of +12.

  • Example 2: the real-life time elapsed between 1/1/1970 and 1/1/2020 (12 leap-years in this 50-year interval) is (365*50+12)*24*3600 + number_leap_seconds and not (365*50+12)*24*3600. But we see datetime.datetime.utcfromtimestamp((365*50+12)*24*3600) is 2020-01-01 00:00:00, so obviously, the leap-seconds haven't been taken in consideration.

  • Linked to What does python return on the leap second, and Unix time and leap seconds


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The number of SI seconds between any two UTC timestamps since 1972-01-01 requires access to the list of leap seconds which have been introduced into UTC. This list is available as part of the IANA tzdata distribution and it can also be obtained from other sources.

Caution is required because the number of SI seconds between what was known as 1970-01-01 and 1972-01-01 is 2x365x24x60x60 + 1.999918 SI seconds because at 1970 the official time was determined not by cesium atoms but by actually measuring the rotation of the earth, so the official seconds were mean solar seconds not SI seconds.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...