What a Unix Timestamp Actually Counts
5 min read
A single growing number, with no built-in concept of time zone — which is exactly why it's so widely used.
A Unix timestamp counts the number of seconds that have elapsed since midnight UTC on 1 January 1970 — an arbitrary reference point chosen when Unix was developed, now universally called "the epoch." Every moment in time since then can be represented as a single, ever-increasing integer.
The appeal for software systems is that this single number has no ambiguity about time zone or daylight saving — those interpretations only get applied when converting the timestamp to a human-readable date, not when storing or comparing it. This makes timestamps easy to sort, compare and calculate durations from without any calendar logic involved.
A common practical snag: some systems use seconds since the epoch, while others (notably JavaScript's native Date object) use milliseconds — a timestamp that looks like it is from the year 50000-something is usually just a seconds-based value being misread as milliseconds, off by a factor of 1,000.
1. The Concept of POSIX Epoch Time
Calculating and storing dates across different calendars, leap years, time zones, and daylight saving shifts is notoriously complex. To solve this in 1971, computer scientists developing the Unix operating system at Bell Labs established a single universal coordinate system for temporal measurement: **Unix Time** (also termed POSIX time or Epoch time). Unix timestamp is defined as: `The exact number of elapsed seconds since January 1, 1970, at 00:00:00 Coordinated Universal Time (UTC), excluding leap seconds.` Regardless of whether a user is sitting in Tokyo, London, or San Francisco, the current Unix timestamp is an identical, singular integer across the entire planet.
2. Seconds vs Milliseconds: The JavaScript Trap
One of the most frequent source-code bugs in cross-stack engineering involves **time resolution units**: - **Standard Unix / POSIX (C, Python, Go, PHP, Linux Kernel):** Measures time in **seconds** (a 10-digit integer in the current era, e.g. `1772600000`). - **JavaScript, Java, and Browser APIs (`Date.now()`):** Measures time in **milliseconds** (a 13-digit integer, e.g. `1772600000000`). Passing a Python Unix timestamp directly into JavaScript's `new Date(timestamp)` without multiplying by 1,000 causes the browser to evaluate a date in January 1970!
3. The Year 2038 Problem (Y2038 / Epochalypse)
Legacy 32-bit Unix systems store timestamps as a **signed 32-bit integer** (`int32`): - The maximum positive value of a signed 32-bit integer is `2^31 - 1 = 2,147,483,647`. - Counting up from January 1, 1970, this integer will overflow on **Tuesday, January 19, 2038, at 03:14:07 UTC**. - Upon reaching 2,147,483,648, the binary bit flips to negative `-2,147,483,648`, causing systems to interpret the date as **December 13, 1901**. This would trigger catastrophic failures in aviation avionics, banking transactions, and embedded industrial controllers. Modern operating systems and databases have transitioned to **signed 64-bit integers** (`int64`), which will not overflow for another 292 billion years.
4. The Leap Second Inconsistency
Because Earth's rotation slows unpredictably due to lunar tidal friction, international metrology bodies insert occasional 'leap seconds' to keep atomic time (UTC) aligned with solar time. However, POSIX Unix time repeats the 86,400th second of the day during a leap second rather than incrementing continuously, causing clock-step jitter that tech companies (Google, AWS) mitigate using 'leap smearing'—gradually stretching seconds across a 24-hour window.
5. Frequently Asked Questions on Unix Time
Why was January 1, 1970 chosen as the epoch? The Unix operating system was being developed around 1971; picking the beginning of the decade (1970-01-01) provided a convenient, clean temporal baseline for early programmers. ### Can Unix timestamps be negative? Yes. Negative timestamps represent dates prior to 1970. For example, `-315619200` represents January 1, 1960. ### How do you convert a Unix timestamp to human-readable date in SQL? In PostgreSQL: `to_timestamp(epoch_col)`; in MySQL: `FROM_UNIXTIME(epoch_col)`.
6. Strategic Takeaways
Always store backend database timestamps in UTC or Unix epoch format. Verify whether your APIs exchange seconds or milliseconds, and ensure database columns use 64-bit integer types to remain Y2038-compliant.