What Is a Unix Timestamp
A Unix timestamp (Unix time, POSIX time, Epoch time) is a way of representing a point in time as a single number: the number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC. This starting point is called the "Unix Epoch." For example, the timestamp 1700000000 corresponds to November 14, 2023, 22:13:20 UTC.
A Unix timestamp is a universal way of storing time, independent of time zones, date formats, or locales. That is why it has become the standard in programming, databases, and APIs.
Why the Count Starts from 1970
The choice of January 1, 1970 as the starting point is historical. The Unix operating system was developed in the late 1960s, and 1970 was chosen as a convenient round date close to the time the system was created. Early implementations stored time as a 32-bit signed integer, which allowed representing dates from December 13, 1901 to January 19, 2038.
Unix Timestamp Formats
Depending on the context, a timestamp may be measured in different units:
- Seconds — the classic Unix timestamp. 10 digits for the current time (e.g.,
1700000000). - Milliseconds — used in JavaScript (
Date.now()), Java (System.currentTimeMillis()). 13 digits (e.g.,1700000000000). - Microseconds — used in some databases and high-precision systems. 16 digits.
- Nanoseconds — used in Go (
time.Now().UnixNano()). 19 digits.
Important: when working with APIs, always clarify what units the timestamp is expected in. Confusing seconds and milliseconds is a common mistake that results in dates in 1970 or the distant future.
The Year 2038 Problem (Y2K38)
A 32-bit signed integer can store values from -2,147,483,648 to 2,147,483,647. The maximum value corresponds to January 19, 2038, 03:14:07 UTC. After that moment, a 32-bit timestamp will "overflow" and become negative — time will roll back to 1901.
This problem is analogous to the famous "Y2K bug," but potentially more serious since it affects numerous embedded systems, databases, and legacy code. The solution is switching to a 64-bit timestamp, which will last for 292 billion years. Most modern systems already use 64-bit representation, but older devices (IoT, industrial controllers) may be vulnerable.
Conversion in Practice
JavaScript
JavaScript works with milliseconds:
- Current timestamp:
Math.floor(Date.now() / 1000)(in seconds). - Date to timestamp:
Math.floor(new Date('2024-01-15').getTime() / 1000). - Timestamp to date:
new Date(1700000000 * 1000).toISOString().
Python
- Current timestamp:
import time; int(time.time()). - Date to timestamp:
import datetime; int(datetime.datetime(2024, 1, 15).timestamp()). - Timestamp to date:
datetime.datetime.fromtimestamp(1700000000).
PHP
- Current timestamp:
time(). - Date to timestamp:
strtotime('2024-01-15'). - Timestamp to date:
date('Y-m-d H:i:s', 1700000000).
SQL
- MySQL:
UNIX_TIMESTAMP()andFROM_UNIXTIME(1700000000). - PostgreSQL:
EXTRACT(EPOCH FROM NOW())andTO_TIMESTAMP(1700000000).
Unix Timestamp and Time Zones
A Unix timestamp is always stored in UTC. This is its main advantage: the same number unambiguously defines a point in time regardless of the time zone. Conversion to local time happens when displaying to the user.
A common mistake: creating a timestamp from local time without specifying a time zone. The function strtotime('2024-01-15 12:00:00') in PHP will use the server's time zone, which can produce different results on different servers. Always specify the time zone explicitly or work in UTC.
Unix Timestamp in APIs
When designing an API, you have two main formats for transmitting dates:
- Unix timestamp — compact, easy to compare and sort, format-independent. But less human-readable.
- ISO 8601 (
2024-01-15T12:00:00Z) — human-readable, includes time zone information. The standard for REST APIs.
Many APIs support both formats. When working with data containing timestamps, it is convenient to use our JSON formatter to visualize the response structure.
Notable Dates in Unix Time
0— January 1, 1970, 00:00:00 UTC — the Unix Epoch.1000000000— September 9, 2001, 01:46:40 UTC — the "gigasecond."2000000000— May 18, 2033, 03:33:20 UTC — stay tuned!2147483647— January 19, 2038, 03:14:07 UTC — the 32-bit timestamp limit.
Frequently Asked Questions
Can a Unix timestamp be negative?
Yes, negative values represent dates before January 1, 1970. For example, -86400 is December 31, 1969. Most modern systems handle negative timestamps correctly, but some older implementations do not.
Does Unix timestamp account for leap seconds?
No. Unix time does not account for leap seconds — it assumes every day has exactly 86,400 seconds. When a leap second is added, the Unix timestamp "freezes" or repeats. For most applications this is insignificant, but it is critical for high-precision systems (GPS, scientific calculations).
How can I convert a Unix timestamp to a date online?
Open our Unix timestamp converter, enter the number, and get a date in a convenient format. Or enter a date and get the corresponding timestamp. The tool supports both seconds and milliseconds and shows the result in your local time zone.
Why is Unix timestamp so popular in programming?
A single number instead of a complex date structure. No time zone issues (always UTC). Easy to compare (if timestamp_a > timestamp_b), sort, and do arithmetic (the difference between two timestamps is an interval in seconds). Compact to store in a database (4 or 8 bytes). Supported by all languages and platforms.