Home › Guides › Developer › Unix timestamps, time zones and the 2038 problem

Unix timestamps, time zones and the 2038 problem

What a Unix timestamp is, how seconds and milliseconds differ, how time zones affect display and why 32-bit time overflows in 2038.

By the tools4free.dev team · Last reviewed 4 December 2026

A Unix timestamp is the number of seconds that have passed since 00:00:00 UTC on 1 January 1970, known as the Unix epoch. At 12:30:00 UTC on 4 December 2026 the timestamp is 1796387400. It has no time zone: the same number means the same instant everywhere, and the time zone only matters when you display it.

What a timestamp is, and is not

A timestamp is a single integer that counts forward from the epoch. Dates before 1970 are negative: -1 is 23:59:59 UTC on 31 December 1969. Because it counts elapsed seconds in UTC, it is easy to store, compare, sort and subtract. The difference between two timestamps is the number of seconds between them.

POSIX defines Unix time so that every day has exactly 86,400 seconds. Leap seconds are not counted, so Unix time ignores them: the clock is stepped or smeared by the operating system instead. For almost all software this makes no difference, and it is the reason a day always equals 86,400 in timestamp arithmetic.

Seconds, milliseconds and microseconds

Different systems count at different resolutions. The number of digits tells you which one you have, for dates in the present era.

UnitDigits todayExample for 2026-12-04 12:30:00 UTCCommon sources
Seconds101796387400Unix date +%s, JWT claims, many APIs
Milliseconds131796387400000JavaScript Date.now(), Java
Microseconds161796387400000000Some databases and tracing tools
Nanoseconds191796387400000000000Go UnixNano, Python time.time_ns()

Mixing these up is the most common timestamp bug. Pass seconds to a JavaScript Date constructor and you get a date in January 1970, since JavaScript expects milliseconds: new Date(1796387400) is 21 January 1970.

Worked example 1: converting in three languages

The same instant, converted both ways.

// JavaScript: milliseconds
const ts = 1796387400;
console.log(new Date(ts * 1000).toISOString());
// 2026-12-04T12:30:00.000Z
console.log(Date.UTC(2026, 11, 4, 12, 30, 0) / 1000);
// 1796387400   (months are 0-based: 11 is December)

# Python
from datetime import datetime, timezone
print(datetime.fromtimestamp(1796387400, tz=timezone.utc).isoformat())
# 2026-12-04T12:30:00+00:00
print(int(datetime(2026, 12, 4, 12, 30, tzinfo=timezone.utc).timestamp()))
# 1796387400

# Shell (GNU date)
date -u -d @1796387400
# Fri Dec  4 12:30:00 PM UTC 2026
date -u -d '2026-12-04 12:30:00' +%s
# 1796387400

In every case the UTC value is stated explicitly. The JavaScript Date.UTC call counts months from zero, so December is 11, a frequent source of off-by-one-month errors.

Worked example 2: one instant in many time zones

The timestamp 1796387400 does not change. Only its display does:

ZoneLocal timeOffset from UTC
UTC4 December 2026, 12:30+00:00
America/New_York4 December 2026, 07:30-05:00
Asia/Tokyo4 December 2026, 21:30+09:00

Going the other way, the text 2026-12-04T12:30:00+02:00 is 10:30 UTC, which converts to 1796380200, and 2026-12-04T12:30:00-05:00 is 17:30 UTC, which is 1796405400. The offset in the string is part of the data. Parsing the same wall-clock text with different offsets gives different instants.

The Year 2038 problem

Many older systems store the timestamp in a signed 32-bit integer, called time_t in C. The largest value such a number can hold is 2,147,483,647, which is 03:14:07 UTC on 19 January 2038. One second later the value overflows. On two's-complement hardware it wraps to -2,147,483,648, which is 20:45:52 UTC on 13 December 1901. Software then sees a date in the past, which can break expiry checks, certificates, scheduled jobs and file times.

Who is affected:

The fix is to use a 64-bit integer. Modern 64-bit operating systems already do, and 64 bits last for hundreds of billions of years. 32-bit Linux has gained support for 64-bit time through new system calls, and C libraries can build with a 64-bit time_t. An unsigned 32-bit field delays the overflow to 06:28:15 UTC on 7 February 2106, but unsigned values cannot represent dates before 1970. Check any 32-bit timestamp column you own, especially those that store dates in the future.

Timestamps or ISO 8601 strings?

Both identify an instant, and each suits a different job. A numeric timestamp is compact, sorts correctly as a number and is trivial to compare, which makes it a good choice for storage, caches, token expiry and internal calculations. A string in the RFC 3339 profile of ISO 8601, such as 2026-12-04T12:30:00Z, is readable by people, carries its offset and is the safer format for public APIs and log files, because nobody has to guess the unit. A good rule is to store a timestamp or an RFC 3339 string with an explicit offset, exchange RFC 3339 strings between systems, and convert to a local display time only in the user interface. If you do choose a number in an API, document whether it is seconds or milliseconds in the field name or the specification.

Take care with fractional seconds. RFC 3339 allows them (12:30:00.250Z), but a timestamp in whole seconds will drop them. If two events must be ordered within one second, keep milliseconds or finer in storage rather than truncating early.

Common mistakes

Frequently asked questions

Why does time start in 1970?

The early Unix developers needed a recent, convenient starting point, and 1 January 1970 was chosen. It is a convention that stuck.

Does a timestamp include leap seconds?

No. Unix time is defined with 86,400 seconds in every day. When a leap second occurs, systems either repeat a second or smear the adjustment over time.

What is the timestamp for now?

In JavaScript, Math.floor(Date.now() / 1000). In a shell, date +%s. In Python, int(time.time()).

Will my 64-bit system have the 2038 problem?

The operating system probably will not, but your own data might. Check database columns, file formats and any library that stores time in 32 bits.

Try it: convert between timestamps and readable dates in the timestamp converter, which accepts both seconds and milliseconds.

Sources