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.
| Unit | Digits today | Example for 2026-12-04 12:30:00 UTC | Common sources |
|---|---|---|---|
| Seconds | 10 | 1796387400 | Unix date +%s, JWT claims, many APIs |
| Milliseconds | 13 | 1796387400000 | JavaScript Date.now(), Java |
| Microseconds | 16 | 1796387400000000 | Some databases and tracing tools |
| Nanoseconds | 19 | 1796387400000000000 | Go 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:
| Zone | Local time | Offset from UTC |
|---|---|---|
| UTC | 4 December 2026, 12:30 | +00:00 |
| America/New_York | 4 December 2026, 07:30 | -05:00 |
| Asia/Tokyo | 4 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:
- Embedded devices and old firmware that use a 32-bit
time_tand will still be running in 2038. - File formats and protocols with a fixed 32-bit seconds field, including some filesystems and database columns.
- Software that computes future dates, such as a 30-year mortgage or a long certificate, which hits the limit before 2038 arrives.
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
- Seconds versus milliseconds. A 10-digit value is seconds and a 13-digit value is milliseconds. Multiply or divide by 1000 at the boundary and name variables with their unit (
expiresAtSec). - Parsing without a zone. In JavaScript,
new Date('2026-12-04')(date only) is treated as UTC, butnew Date('2026-12-04T00:00:00')(no offset) is treated as local time. They differ unless the machine is on UTC. Always includeZor an offset. - Storing local time. Store UTC, or the timestamp, and convert on display. Local times are ambiguous when clocks go back and non-existent when they go forward.
- Adding 86,400 to mean "tomorrow". It is correct in UTC, but "same time tomorrow in London" can be 23 or 25 hours later across a daylight saving change. Use a calendar library for civil dates.
- Treating a timestamp as unique or monotonic. System clocks are adjusted by NTP and can jump backwards. For measuring durations, use a monotonic clock such as
performance.now()ortime.monotonic(). - Using floating point. Fractional seconds in a float lose precision at nanosecond scale. Store integers in a chosen unit.
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.