Unix Time and Unix Timestamps
What is Unix Time?
Unix time (or ‘unixtime’) is a system that represents a point in time by counting the number of seconds elapsed since a fixed reference moment. That reference is called the Unix epoch (00:00:00 UTC on January 1, 1970).
Unix timestamps basically store values as simple numbers. Many computer systems and Linux machines adopt Unix time as their base timekeeping method.
You’ll see the same idea called different things in the wild — Unix timestamp, epoch time, POSIX time, or just “a Unix stamp.” They all refer to the same value: the number of seconds since the Unix epoch. “Unix time” usually describes the system itself, while “Unix timestamp” tends to mean a specific stored number, but in practice the terms are interchangeable.
Unix Time’s Origins
The idea of Unix time or unixtime came from early Linux and Unix operating systems, intended as a compact and consistent time format. It’s also known as POSIX time in many Linux-based environments.
Different systems have adopted Unix time, where it is used as a unifying data format for time data. The choice of January 1, 1970, as the Unix epoch was arbitrary but provided a solid baseline for inter-system synchronization.
POSIX Time and the ‘date’ Command
On Linux, macOS, and other Unix-like systems, the operating system kernel keeps time as a Unix timestamp internally. POSIX time refers to the same concept, the name simply reflects the IEEE Std 1003.1 specification that formalized the behavior across Unix-like environments. In day-to-day use, POSIX time and Unix time are the same number.
The shell exposes that number through the date utility. Running ‘date +%s’ prints the current Unix timestamp in seconds, and ‘date -d @1700000000‘ converts a stored value back into a readable local date. On macOS the equivalent is ‘date -r 1700000000’. These one-liners are why Unix time is the de-facto language of shell scripts, cron jobs, and log rotation tools.
How to Calculate Unix Time
To compute Unix time, you count the number of non-leap seconds that have passed since the Unix epoch in UTC and exclude leap years and seconds. For example, for any date or dates after 1 January 1970, you subtract the epoch and convert the difference into seconds.
When dealing with time zones, you first convert local times into UTC before doing the calculation. Because Unix time ignores leap seconds, each day is treated as exactly 86,400 seconds, meaning it can diverge from true atomic/UTC time when leap seconds are inserted.
Most days in Unix time are counted as exactly 86,400 seconds. This means adding one day typically increases the timestamp by 86,400 (leap-second days are the only exception).
When using JavaScript, we can get the current Unix value by calling Date.now() (which gives milliseconds since the epoch), then dividing by 1000 to get the Unix stamp in seconds.
Unix Timestamp Format and Examples
A standard Unix timestamp is a 10-digit integer measured in seconds. For example, 1700000000 corresponds to November 14, 2023 at 22:13:20 UTC. Add three more digits and you have milliseconds (13 digits), which is what JavaScript and many web APIs return by default.
The format is just a count, there is no separator, no time zone tag, no calendar metadata. Everything is encoded in the number itself. A few reference points make the scale easier to read:
| Date and Time (UTC) | Unix Timestamp |
| January 1, 1970 00:00:00 | 0 |
| July 20, 1969 20:17:40 | -14182940 |
| January 1, 2000 00:00:00 | 946684800 |
| September 9, 2001 01:46:40 | 1000000000 |
| January 1, 2024 00:00:00 | 1704067200 |
| January 19, 2038 03:14:07 | 2147483647 |
Dates before the epoch are perfectly valid, they just carry a minus sign. The value -14182940 lands on the exact moment Apollo 11 touched down on the Moon. The last row in the table marks the upper limit of a signed 32-bit Unix timestamp, which is where the Year 2038 problem kicks in.
Getting a Unix Timestamp in Code
Every mainstream language exposes Unix time through a one-liner. The values they return are identical, since the timestamp is timezone-independent by definition.
- JavaScript: Math.floor(Date.now() / 1000) for seconds, or Date.now() for milliseconds.
- Python: import time; int(time.time()) for whole seconds; drop the int() to keep sub-second precision.
- Bash / Linux: date +%s prints the current Unix timestamp directly in the terminal.
- PHP: time() for seconds, microtime(true) for fractional precision.
- Java: System.currentTimeMillis() / 1000L for seconds.
- Go: time.Now().Unix().
- SQL: UNIX_TIMESTAMP() in MySQL, EXTRACT(EPOCH FROM NOW()) in PostgreSQL.
Converting the other way, from a stored timestamp back to a human-readable date, is just as built-in. In Python it’s datetime.utcfromtimestamp(ts); in JavaScript, new Date(ts * 1000).toISOString(). Always be explicit about the target time zone when displaying, since the timestamp itself carries no zone information.
Seconds, Milliseconds, and Higher Precision
The original Unix timestamp counts whole seconds, but modern systems often need finer resolution. The convention is easy to spot by digit count: 10 digits is seconds, 13 digits is milliseconds, 16 digits is microseconds, and 19 digits is nanoseconds.
JavaScript defaults to milliseconds, Python and most databases default to seconds, and high-frequency systems like trading engines or distributed tracing tools often work in nanoseconds. When you receive a timestamp from an unfamiliar source, glance at the digit count before parsing, silently mixing seconds and milliseconds is one of the most common date bugs in production code, and it places the result 1 000 times off in either direction.
Unix Time’s Common Uses
Unix time is commonly used for storing timestamps in databases, logs, APIs, and file formats. Systems store time values in a uniform way using this time format.
Because it avoids ambiguity around time zones and local times, this data format is preferred when exchanging values between systems. Many web APIs return Unix timestamps so clients and servers can translate them into human-readable date formats. It is also used in sorting by time order, scheduling, and in event logging across computer systems.
The Year 2038 Problem
Unix time has one famous edge case. Systems that store the value in a signed 32-bit integer can only count up to 2,147,483,647 seconds, and that ceiling is hit at 03:14:07 UTC on January 19, 2038. The next tick wraps the number into the negative range, putting the date back in 1901. It’s sometimes called Y2038 or the Unix Millennium Bug.
Most modern operating systems, databases, and programming languages have already moved to 64-bit timestamps, which push the limit hundreds of billions of years into the future. The risk now lives mainly in legacy code, embedded firmware, older file formats, and 32-bit binaries that have never been recompiled. Auditing long-lived systems for hard-coded 32-bit time types is the practical takeaway.
FAQs
How many digits does a Unix timestamp have?
Ten digits for seconds (until the year 2286), thirteen for milliseconds. A timestamp with a different length is almost always a precision mismatch and should be sanity-checked before parsing.
Is Unix time the same as UTC?
Not exactly. Unix time counts seconds from a fixed UTC moment, so it’s anchored in UTC by definition, but it doesn’t track leap seconds the way true UTC does. For most applications the difference is invisible; for high-precision timing it isn’t.
Can a Unix timestamp be negative?
Yes. Negative values represent dates before January 1, 1970. The math is valid, though not every library handles them gracefully, test before relying on them.
What’s the difference between Unix time and epoch time?
In everyday use, none. Both terms describe seconds since January 1, 1970 UTC. “Epoch time” is slightly more generic because other systems define their own epochs (the .NET epoch, the Mac OS epoch, and so on), but in 99% of contexts people mean Unix time.
