Understanding Unix Timestamps

A look at what it means to represent time as a single number.

A Unix timestamp boils a point in time down to a single number: the count of seconds that have ticked by since one fixed reference moment. It's everywhere in computing for a simple reason — storing and comparing times this way is clean and consistent. Below we'll unpack how it works. There's a timestamp converter on this site if you'd like to see a few values translated as you go.

The reference point

That reference moment is midnight on January 1, 1970, in Coordinated Universal Time, usually just called the epoch. A timestamp is simply how many seconds have passed since then. So a timestamp of zero is the epoch, larger numbers are later moments, and anything before 1970 shows up as a negative number.

Why this format is used

Squeezing time into one number buys you a few nice things. It's compact and easy to store. Comparing two times is trivial, since a bigger number is always the later one. And finding the gap between two times is just subtraction. None of this is especially readable to a human, but for software it's hard to beat.

Seconds and milliseconds

The classic Unix timestamp counts whole seconds, but plenty of systems count milliseconds instead — thousandths of a second since the epoch. That makes a millisecond value a thousand times larger than the same moment in seconds. It's worth knowing which one you're holding, because reading a millisecond value as seconds (or the other way around) lands you wildly off from the time you meant.

Time zones

A Unix timestamp pins down a specific moment in Coordinated Universal Time, and it carries no time zone of its own. To show it as a local time, you apply the right time zone offset. That separation is actually handy: the same timestamp means the same instant everywhere on earth, and the local-time conversion only enters the picture at the moment you display it.

The year 2038 consideration

Some older systems store timestamps in a format that runs out of room at a certain point in 2038 — go past it and the value no longer fits. Modern systems mostly use a wider format that pushes that ceiling far into the future. It's a known thing to watch for in software that reasons about dates over very long spans.

Summary

A Unix timestamp is a point in time expressed as the seconds since midnight on January 1, 1970, in Coordinated Universal Time. It's compact and easy to compare and do math with. Just take care to tell second-based and millisecond-based values apart, and to apply a time zone conversion when you show a timestamp as local time.

Try the timestamp converter · Back to all articles