Software Development

How Computers Keep Time: Unix Timestamps, UTC, Time Zones and DST

Why every timestamp is really a count of seconds, and how software turns it into the right time on your wall clock

Zarton EditorsNov 6, 2026 · 7 min read
Listen to this article

A meeting invite shows up an hour early. A nightly job runs twice one Sunday in November. A log line says an error happened before the request that caused it. None of these are exotic bugs. They are what happens when software treats time as a simple number on a clock face.

This guide explains how computers keep time: what a Unix timestamp really counts, why UTC is the anchor, how the IANA time zone database turns an instant into a wall-clock reading, where daylight saving time sets traps, and what leap seconds and the Year 2038 problem mean for code you write today.

Unix time: one number for every instant

Most systems store a moment as a Unix timestamp: the number of seconds elapsed since the "epoch," midnight UTC on January 1, 1970. Right now that number is a little under 1.8 billion. JavaScript's Date.now() and many databases use milliseconds instead, but the idea is the same.

The beauty of a timestamp is that it has no time zone. The value is identical in Tokyo and Toronto, so comparing two events, sorting logs or computing "five minutes from now" is plain arithmetic. You can see it from any Linux or macOS shell:

$ date +%s
1794016800

$ date -u -d @2147483647      # GNU date
Tue Jan 19 03:14:07 UTC 2038

There is one quiet catch. POSIX Unix time pretends every day has exactly 86,400 seconds. Real UTC occasionally inserts a leap second, and the timestamp simply ignores it. The time zone database documentation notes that its default "posix" configuration works this way, with an optional "right" configuration for software that must count every atomic second.

From an instant to a wall clock: how time zones work

A timestamp tells you when something happened. People want to know what their clock said. Getting from one to the other needs two things: an offset from UTC, and the rules for when that offset changes.

Offsets are not time zones

An offset like -05:00 is a fixed distance from UTC. A time zone like America/New_York is a history of offsets: Eastern Standard Time in winter, Eastern Daylight Time in summer, and whatever rules lawmakers have applied over the decades. Storing "-05:00" for a user in New York will be wrong for roughly two thirds of the year.

The IANA tz database

Those histories live in the tz database (also called tzdb or zoneinfo). It is a public-domain collection maintained by volunteers and hosted by IANA, and it ships inside GNU/Linux, Android, macOS, Windows, MySQL and countless language runtimes. Key facts from the project's own documentation:

  • Names follow Area/Location, using a continent or ocean plus the largest city in the region, such as Europe/Paris or America/Phoenix.
  • Each zone covers places whose clocks have agreed since 1970, recording offsets, daylight saving periods and abbreviations.
  • There is no fixed release schedule. New versions typically appear every few months, whenever a government changes its rules.
  • Governments are asked to announce changes well in advance, because phones, servers and appliances all need time to receive updated data.

If a country changes its clocks on short notice, devices with stale tz data show the wrong local time until they update.

Daylight saving time: the gap and the overlap

Daylight saving transitions create two kinds of awkward local times. In most of the United States, clocks jump from 2:00 to 3:00 on the second Sunday in March, so 2:30 a.m. that day never exists. On the first Sunday in November they fall back from 2:00 to 1:00, so 1:30 a.m. happens twice.

Good date libraries make you choose what to do. When asked for a local time inside a gap, they shift forward or backward; for a time in an overlap, they let you pick the earlier or later instant. Code that adds "24 hours" when it means "same time tomorrow" will drift by an hour across a transition, which is why modern APIs separate exact durations from calendar arithmetic.

Writing time down: ISO 8601 and RFC 3339

When timestamps leave your program, in JSON, logs or URLs, use a standard text format. RFC 3339, published by the IETF in July 2002, is a strict profile of ISO 8601 built for internet protocols:

2026-11-06T18:30:00Z          # UTC ("Z" means offset 00:00)
2026-11-06T10:30:00-08:00     # same instant, Pacific Standard Time
2026-11-06T18:30:00.250Z      # fractional seconds are allowed

A few rules worth knowing: the offset is local time minus UTC, the letters T and Z should be uppercase when generating, hours run only 00 to 23, and a seconds value of 60 is allowed to represent a leap second. The RFC also gives -00:00 a special meaning: the UTC time is known but the local offset is not.

Parsing user-supplied strings brings encoding pitfalls too; see how Unicode and UTF-8 work.

Leap seconds and the Year 2038 problem

Leap seconds are on their way out

Earth's rotation is slightly irregular, so since 1972 timekeepers have added 27 leap seconds to keep atomic time close to solar time, the last at the end of 2016. Each one is an unpredictable disruption for systems that expect smooth time. In November 2022 the General Conference on Weights and Measures voted to stop adding leap seconds by 2035. Some operators "smear" a leap second over several hours instead, though the tz documentation warns this is unsuitable when exact UTC matters.

The 2038 rollover

A signed 32-bit integer can count up to 2,147,483,647. As a Unix timestamp, that is 03:14:07 UTC on January 19, 2038. One second later, a 32-bit counter wraps to a negative number that reads as December 13, 1901. Modern 64-bit systems are safe, and the Linux kernel has supported 64-bit timestamps on 32-bit hardware since version 5.6 in 2020. The risk lives in old embedded devices, industrial controllers, file formats and database columns that still use 32 bits, and in software that already projects dates decades ahead.

What to store, and when

Most time bugs come from storing the wrong kind of value:

What you are recordingStore thisExample
Something that already happened (log, order, login)A UTC instant2026-11-06T18:30:00Z
A future event people attend in personLocal date-time plus IANA zone name2027-03-14 09:00 + America/Chicago
A date with no time (birthday, due date)A plain calendar date2026-12-25
How long something tookA duration from a monotonic clock842 ms

The future-event row surprises people. If you convert next year's 9:00 a.m. meeting to UTC today and the region changes its daylight saving rules in the meantime, your stored instant will now be an hour off. Keeping the local time and zone lets the software recompute with the newest rules. Indexing those columns well is its own topic, covered in how database indexes work.

In code

Python's standard library has used the tz database through zoneinfo since version 3.9, and JavaScript is gaining the Temporal API, which shipped in Chrome 144 as a stage 3 proposal and separates instants, zoned date-times and plain dates into distinct types:

# Python
from datetime import datetime, timezone
from zoneinfo import ZoneInfo

now = datetime.now(timezone.utc)                 # store this
local = now.astimezone(ZoneInfo("Asia/Tokyo"))   # show this
print(now.isoformat(), local.isoformat())

// JavaScript (Temporal)
const meeting = Temporal.ZonedDateTime.from(
  "2027-03-14T09:00[America/Chicago]"
);
const tomorrow = meeting.add({ days: 1 }); // calendar day, DST-aware

Key takeaways

  • A Unix timestamp counts seconds since 1970-01-01 UTC and has no time zone, which makes it ideal for storing past events.
  • A time zone is a history of offsets; store IANA names like Europe/Paris, never a bare offset.
  • Daylight saving creates local times that are skipped or repeated; schedule critical jobs in UTC.
  • Exchange timestamps as RFC 3339 strings with an explicit offset or Z.
  • Keep tz data updated, retire 32-bit time fields before 2038, and measure durations with a monotonic clock.

Frequently asked questions

Is a Unix timestamp the same everywhere in the world?

Yes. It counts seconds from a single moment in UTC, so the same instant has the same value in every time zone. Only its display as local time differs.

Should I store dates in UTC or local time?

Store past events as UTC instants. For future events tied to a place, such as meetings or appointments, store the local date-time plus the IANA zone name so rule changes are applied correctly.

What is the difference between ISO 8601 and RFC 3339?

ISO 8601 is a broad international standard with many optional forms. RFC 3339 is a narrower profile of it for internet protocols that requires a full date, time and offset, which makes it easier to parse reliably.

Will the Year 2038 problem affect my computer?

A modern 64-bit operating system is not affected. The risk is in older 32-bit embedded devices, legacy software and data formats that still store time as a 32-bit signed integer.

Sources

Comments

No comments yet — be the first to share your thoughts.

Join the discussion

Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Keep reading

All posts

Run your whole business from one conversation.

Get startedTalk to us