Unix timestamps explained: how they work and where they go wrong
Numbers like 1795226400 show up in server logs, databases and API responses. This guide explains how to read them, why the same number is right in New York and in London, and where conversions usually break.
A count of seconds since 1970
A Unix timestamp is the number of seconds since the epoch, 1 January 1970 at 00:00:00 UTC. POSIX defines it with a calendar formula in which every day counts as exactly 86,400 seconds. For example, 1795226400 is 21 November 2026 at 02:00:00 UTC, which was 9:00 PM on 20 November in New York. Moments before 1970 are negative: -86400 is 31 December 1969 at 00:00 UTC.
Because it is a single integer, a timestamp is easy to store, compare and subtract. The difference between two timestamps is the time between them in seconds, with no month lengths or leap years to worry about.
Seconds or milliseconds
Many systems store the epoch in finer units, and the digit count gives it away. For any date between 9 September 2001 and 20 November 2286, a timestamp in seconds has exactly 10 digits:
| Unit | Digits | 2026-11-21 02:00 UTC |
|---|---|---|
| Seconds | 10 | 1795226400 |
| Milliseconds | 13 | 1795226400000 |
| Microseconds | 16 | 1795226400000000 |
| Nanoseconds | 19 | 1795226400000000000 |
JavaScript's Date.now() and Java's System.currentTimeMillis() return milliseconds; PHP's time() returns seconds. Python's time.time() returns seconds with a fraction, such as 1795226400.25, and Go's UnixNano() returns nanoseconds. Mixing them up is the most common bug. Milliseconds read as seconds land in the year 58858, and seconds read as milliseconds land on 21 January 1970. A date that shows up as January 1970 almost always means the units are swapped.
A timestamp has no time zone
One timestamp points to the same instant everywhere on Earth. The time zone only comes in when that instant is shown as a wall-clock time. 1795226400 is 9:00 PM in New York on 20 November, 2:00 AM in London and 10:00 AM in Singapore on the 21st. Daylight saving time changes the offset between those cities twice a year, but never the timestamp.
The working rule: store times as timestamps or UTC, and convert to the user's zone only for display. Use IANA zone names such as America/New_York or Europe/London rather than a fixed offset like −5, so daylight saving rules are applied for you. When a local time falls in the spring-forward gap, 2:30 AM on 8 March 2026 in New York for instance, it never existed, and libraries differ in how they handle it, often by quietly shifting it an hour.
Watch out for date strings with no zone. In JavaScript, new Date('2026-11-21') is read as midnight UTC, while new Date('2026-11-21T09:00') is read as local time on the device. Two nearly identical lines, two different reference zones.
Leap seconds
UTC occasionally inserts a leap second to stay close to the Earth's rotation. There have been 27 since 1972; the last was 23:59:60 UTC on 31 December 2016, and since then UTC has been 37 seconds behind atomic time (TAI). Unix time ignores leap seconds, because every day counts as exactly 86,400 seconds. So the difference between two timestamps on either side of the end of 2016 is one second shorter than the time that really passed. When a leap second happens, systems either repeat a second or spread it out; Google's public NTP servers, for example, slow their clocks over 24 hours from noon to noon UTC.
No further leap second is scheduled. The IERS Bulletin C of July 2026 announced none for the end of December 2026, and in 2022 the General Conference on Weights and Measures (CGPM) decided to widen the allowed UT1−UTC difference in or before 2035, with the aim of keeping UTC free of interruptions for at least a century.
The year 2038 problem
Older systems store timestamps as a signed 32-bit integer, whose largest value is 2,147,483,647: 19 January 2038 at 03:14:07 UTC. One second later the value wraps to −2,147,483,648, which reads as 13 December 1901. An unsigned 32-bit value lasts until 7 February 2106, and 64 bits are effectively unlimited.
The old limit survives in plenty of places. MySQL's TIMESTAMP column only goes up to 2038-01-19 03:14:07 UTC, while DATETIME runs to the year 9999. And the problem doesn't wait for 2038: a 15-year loan that starts today ends in 2041, so software that computes its schedule is already past the limit.
Converting in common languages
JavaScript:
Math.floor(Date.now() / 1000) // now
const d = new Date(1795226400 * 1000);
d.toISOString();
// '2026-11-21T02:00:00.000Z'
d.toLocaleString('en-US',
{ timeZone: 'America/New_York' });
// '11/20/2026, 9:00:00 PM'
Date.parse('2026-11-20T21:00:00-05:00')
/ 1000; // 1795226400
Python 3.9 and later:
from datetime import datetime
from zoneinfo import ZoneInfo
ny = ZoneInfo('America/New_York')
datetime.fromtimestamp(1795226400, ny)
# 2026-11-20 21:00:00-05:00
dt = datetime(2026, 11, 20, 21, 0,
tzinfo=ny)
int(dt.timestamp()) # 1795226400
PHP, SQL and the shell:
// PHP
$d = new DateTime('@1795226400');
$d->setTimezone(
new DateTimeZone('America/New_York'));
echo $d->format('c');
// 2026-11-20T21:00:00-05:00
-- PostgreSQL
SELECT to_timestamp(1795226400);
-- MySQL, uses the session time zone
SELECT FROM_UNIXTIME(1795226400);
date +%s # now
date -u -d @1795226400 # Linux
date -u -r 1795226400 # macOS
Converting on swift.id
- Open the Unix Timestamp Converter. The top shows the Current Unix timestamp (seconds) and the value In milliseconds, each with a Copy button.
- Paste a number into Unix timestamp. With the unit on Automatic, values below 1011 are read as seconds, below 1014 as milliseconds, below 1017 as microseconds, and anything larger as nanoseconds. Pick the unit yourself if the guess is wrong. Fractions such as Python's output and thousands separators are accepted.
- Read the result as local time, UTC, ISO 8601, RFC 2822 or relative time, and copy the line you need.
- For the other direction, fill in the Date and Time under Date to timestamp and choose the Time zone. If the time you pick fell in a daylight saving gap or overlap, the tool says so and shows which moment it used.
Timestamps also hide inside version 7 UUIDs; the UUID v4 vs v7 guide shows how to read one.
Questions
Why is my converted time off by several hours?
Can a timestamp be negative?
Is JavaScript safe from the 2038 problem?
Date holds milliseconds in a 64-bit floating-point number and reaches the year 275760. The trouble starts when that value is sent to a database column or another program that is still 32-bit.Should an API use timestamps or ISO 8601 dates?
created_at_ms. An ISO 8601 date needs its offset, such as 2026-11-20T21:00:00-05:00, or a Z suffix for UTC.