Is a day always 86,400 epoch seconds long?

Whenever doing calendrical calculations, it is almost always better to use whatever API the platform provides, such as Python's datetime and calendar modules, or a mature high-quality library, than it is to write "simpler" code yourself. Date and calendar APIs are ugly and complicated, but that's because real-world calendars have a lot of weird behavior.

For example, if it is "10:00:00 AM" right now, then the number of seconds to "10:00:00 AM tomorrow" could be a few different things, depending on what timezone(s) you are using, whether DST is starting or ending tonight, and so on.

Any time the constant 86400 appears in your code, there is a good chance you're doing something that's not quite right.

And things get even more complicated when you need to determine the number of seconds in a week, a month, a year, a quarter, and so on. Learn to use those calendar libraries.


According to Wikipedia,

UTC days are almost always 86 400 s long, but due to "leap seconds" are occasionally 86 401 s and could be 86 399 s long (though the latter option has never been used as of December 2010); this keeps the days synchronized with the rotation of the Earth (or Universal Time).

I expect that a double leap second could in fact make the day 86402s long, if that were to ever be used.

EDIT again: second guessed myself due to confusing python documentation. time.mktime always returns UTC epoch seconds. There done. : )


Number of seconds in a day depends on time system that you use e.g., in POSIX, a day is exactly 86400 seconds by definition:

As represented in seconds since the Epoch, each and every day shall be accounted for by exactly 86400 seconds.

In UTC, there could be a leap second included i.e., a day can be 86401 SI seconds (and theoretically 86399 SI seconds). As of Jun 30 2015, it has happened 26 times.

If we measure days by apparent motion of the Sun then the length of a (solar) day varies through the year by ~16 minutes from the mean.

In turn it is different from UT1 that is also based on rotation of the Earth (mean solar time). An apparent solar day can be 20 seconds shorter or 30 seconds longer than a mean solar day. UTC is kept within 0.9 seconds of UT1 by the introduction of occasional intercalary leap seconds.

If you define a day by local clock then it may be very chaotic due to bizarre political timezone changes. It is not correct to assume that a day may change only by an hour due to DST.