Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix time and leap seconds

Regarding Unix (POSIX) time, Wikipedia says:

Due to its handling of leap seconds, it is neither a linear representation of time nor a true representation of UTC.

But the Unix date command does not seem to be aware of them actually

$ date -d '@867715199' --utc Mon Jun 30 23:59:59 UTC 1997 $ date -d '@867715200' --utc Tue Jul  1 00:00:00 UTC 1997 

While there should be a leap second there at Mon Jun 30 23:59:60 UTC 1997.

Does this mean that only the date command ignores leap seconds, while the concept of Unix time doesn't?

like image 727
Campa Avatar asked May 14 '13 09:05

Campa


People also ask

What is Unix time in seconds?

Unix time is a way of representing a timestamp by representing the time as the number of seconds since January 1st, 1970 at 00:00:00 UTC. One of the primary benefits of using Unix time is that it can be represented as an integer making it easier to parse and use across different systems.

How does Unix time handle leap years?

On leap years the timestamps an additional second must be added to the UTC to account for the change in the earth rotation and other external factors. The UNIX timestamp must consider for this leap second by calculating an extra second at midnight.

Does Epoch time include leap seconds?

It is often said that Unix time is the number of seconds since the “Epoch,” midnight of January 1, 1970. But it's not that simple because leap seconds are not included. corresponding to the number of seconds in a day times the number of days since New Year's Day 1970, including 12 leap days.

Why is Jan 1 1970 the epoch?

Unix was originally developed in the 60s and 70s so the "start" of Unix Time was set to January 1st 1970 at midnight GMT (Greenwich Mean Time) - this date/time was assigned the Unix Time value of 0. This is what is know as the Unix Epoch.


1 Answers

The number of seconds per day are fixed with Unix timestamps.

The Unix time number is zero at the Unix epoch, and increases by exactly 86400 per day since the epoch.

So it cannot represent leap seconds. The OS will slow down the clock to accommodate for this. The leap seconds is simply not existent as far a Unix timestamps are concerned.

like image 166
Thomas Jung Avatar answered Oct 16 '22 21:10

Thomas Jung