What is epoch time?

Epoch time, also called Unix time or POSIX time, is a single number: the count of seconds since midnight UTC at the start of 1 January 1970.

The definition

Pick an instant, call it zero, and count seconds from it. For Unix time that instant, the epoch, is 1970-01-01T00:00:00Z. One hour later the time was 3600. A day later it was 86400. As this page was written it was a little under 1.8 billion.

The number is the same everywhere on Earth at the same moment. It has no time zone, no daylight saving time, no month lengths and no date format. Those belong to the calendar, and are applied only when the number is turned into a date for a person to read.

"Epoch time", "Unix time", "Unix timestamp" and "POSIX time" all mean this count. Strictly, an epoch is just a reference point and other systems have other ones, but when a developer says "epoch" with no qualifier, they mean 1970.

Why 1970?

It was a convenient recent date when Unix was being written at Bell Labs around 1970. The earliest versions counted sixtieths of a second in a 32-bit number, which ran out in under two and a half years, and the origin was moved more than once. The system settled on whole seconds from the start of 1970, which in a signed 32-bit integer reaches from 1901 to 2038. There is nothing significant about the date itself.

What the count leaves out

POSIX defines the conversion from a UTC date to seconds with plain arithmetic in which every day has exactly 86,400 seconds. Real UTC days occasionally have 86,401, because of leap seconds. Unix time pretends they do not happen, so it is not a true count of elapsed seconds: it is off by the 27 leap seconds added since 1972. The benefit is that dividing by 86,400 always gives the day number and converting to a date needs no table.

Why programs use it

  • Comparing and sorting two instants is integer comparison.
  • Durations are subtraction: end - start seconds.
  • No ambiguity. 03/04/2024 01:30 could be two different days and, on the night the clocks go back, two different instants. 1712107800 is one.
  • Compact. Four or eight bytes, against 20 or more characters for a formatted date.

The cost is that nobody can read it, which is what the converter is for, and that it cannot represent "9 am in whatever zone the user is in" or a date without a time. For calendar concepts like those, store the date and the zone instead.

Units and other epochs

The original unit is the second, but milliseconds (JavaScript, Java), microseconds (PostgreSQL, Python's datetime) and nanoseconds (Go) are all common: see seconds or milliseconds. Other systems count from other origins:

SystemEpochUnit
Unix, POSIX1970-01-01seconds
Windows FILETIME1601-01-01100 nanoseconds
.NET DateTime.Ticks0001-01-01100 nanoseconds
NTP1900-01-01seconds, 32-bit, wraps in 2036
GPS1980-01-06weeks and seconds, no leap seconds
Excelthe end of 1899days
Apple Cocoa (NSDate)2001-01-01seconds

To turn a Windows FILETIME into Unix seconds, divide by 10,000,000 and subtract 11,644,473,600, the number of seconds between 1601 and 1970.

Questions

Is epoch time the same as Unix time?

In everyday use, yes. Both mean the number of seconds since 1970-01-01T00:00:00Z. "Epoch" on its own just means a reference point, and other systems use different ones.

Is Unix time the same in every time zone?

Yes. It counts from an instant fixed in UTC, so at any moment every correctly set clock in the world has the same Unix time.

What was the Unix time at the epoch?

Zero. Times before 1970 are negative numbers.