Understanding UNIX time ======================= There is a common misconception about UNIX time. It is the idea that UNIX time tells you the number of seconds that have passed since 1970-01-01T00:00:00+00:00 (the UNIX epoch). That is not the case. Instead, UNIX time is a way of rewriting an ISO 8601 timestamp as a number. The key difference is about leap seconds. When a leap second is inserted or removed, the number of seconds in that ISO day changes to 86401 or 86399. You have to consider this when you count the number of seconds that have passed since the UNIX epoch. You cannot just count the days and multiply that number with 86400. This also means that if you are given an ISO timestamp in the future, you cannot calculate how many seconds will have passed since the UNIX epoch by then, because you cannot predict leap seconds. But UNIX time is different. In UNIX time, every ISO day has exactly 86400 seconds (which also means that every UNIX timestamp of a UTC midnight is divisible by 86400). If a leap second is inserted (i.e. the seconds go 59, 60, 00), then the UNIX timestamp of the "60" second is copied from the "59" or "00" second. If a leap second is removed (i.e. the seconds go 58, 00), then the UNIX timestamp for the "59" second is skipped. This means that you can calculate the UNIX timestamp for any ISO timestamp, even future ones. What you cannot do, though, is blindly increment a counter every second and expect it to stay in sync with UNIX time (becuase then it misses the reused and skipped values due to leap seconds). Unlike the number of seconds per day, which always stays the same in UNIX time, the number of days in a year does not: it still depends on leap years. But you can always calculate with certainty whether a year is a leap year as follows: ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) This makes UNIX time a safe and useful numerical representation of calendrical data (as long as you use 64-bit variables instead of 32-bit variables). Copyright (C) 2023 Daniel Kalak Licensed under CC-BY-ND-4.0 .