The Complete Guide to Unix Epoch Time & Timestamps
Learn why modern operating systems measure time from January 1, 1970, how to identify timestamp units, and how to avoid the Year 2038 bug.
Every computer, mobile phone, web server, and database in the world relies on a standardized, universal timekeeper known as Unix Time (also called Epoch Time or POSIX Time). Rather than dealing with differing country calendars, political Daylight Saving Time adjustments, and varying timezone offsets, Unix time is simply the total count of elapsed seconds since the arbitrary reference point of midnight UTC on January 1, 1970.
Because Unix timestamps are plain integers, sorting records chronologically, computing time deltas, and synchronizing distributed database servers becomes a fast, arithmetic calculation.
Seconds vs. Milliseconds vs. Microseconds: How to Tell Them Apart
A common source of bugs in software development is passing a timestamp in seconds to an API that expects milliseconds, or vice versa (which causes dates to display in 1970 or far in the future). You can immediately identify the unit by counting the number of digits:
| Precision Unit | Digit Count | Example Timestamp | Common Environments |
|---|---|---|---|
| Seconds (s) | 10 digits | 1729789200 | Linux kernel, Python, PHP, Go, Redis, JWT Tokens |
| Milliseconds (ms) | 13 digits | 1729789200000 | JavaScript Date.now(), Java, MongoDB, Stripe webhooks |
| Microseconds (μs) | 16 digits | 1729789200000000 | C++ std::chrono, PostgreSQL timestamp, system profiling |
| Nanoseconds (ns) | 19 digits | 1729789200000000000 | Go time.Now().UnixNano(), high-frequency trading, CPU clocks |
The Year 2038 Problem (Y2K38): 32-Bit Integer Overflow
Legacy 32-bit systems store the Unix timestamp as a signed 32-bit integer (`int32`). The maximum positive integer value that can be held in 31 bits (with 1 bit reserved for sign) is 2,147,483,647.
On Tuesday, January 19, 2038 at 03:14:07 UTC, this counter will reach capacity. One second later, the integer overflows into negative territory (`-2,147,483,648`), which systems interpret as December 13, 1901!
Modern operating systems, 64-bit processors, and databases have transitioned to 64-bit signed integers (`int64`). With 64 bits, the maximum epoch time is approximately 292 billion years into the future, safely resolving the issue for all human civilization.
Best Practices for Storing Dates in Databases and Web APIs
Follow these essential software architecture guidelines when managing dates: