Developers · 6 min read

Unix Timestamps Explained: Epoch Time, Milliseconds and Timezones

Open any log file, API response or database row and you will eventually meet a number like 1767225600 where a date should be. It is a Unix timestamp: a simple, timezone-free way for computers to agree on a moment in time. Once you know how to read it, debugging expiry times, scheduled jobs and event logs gets much easier.

What a Unix timestamp is

A Unix timestamp counts the seconds that have passed since 00:00:00 UTC on 1 January 1970, a moment called the Unix epoch. The value 0 is that exact instant, and 1767225600 is midnight UTC on 1 January 2026.

Leap seconds are not counted, so every day is treated as exactly 86,400 seconds long. That makes the arithmetic simple: adding 3,600 always moves a timestamp forward by one hour.

Seconds versus milliseconds

Different systems use different units, and mixing them up is a classic bug. Current timestamps in seconds have ten digits, around 1.7 billion. In milliseconds they have thirteen digits, around 1.7 trillion.

  • JavaScript Date.now() and new Date().getTime() return milliseconds.
  • Most databases, the JWT exp, iat and nbf claims, and many APIs use seconds.
  • A date in the year 1970 when you expected today usually means seconds were read as milliseconds; a date tens of thousands of years away means the opposite.

Why timestamps ignore timezones

A timestamp identifies one instant that is identical everywhere on Earth. A timezone only matters when you display it as a calendar date and clock time. The same timestamp is 14:00 in London and 09:00 in New York.

This is why the safest rule is to store and transmit time as UTC or as a timestamp, and to convert to the user's local timezone only at the last moment, when showing it on screen.

Timestamps you will meet in practice

JSON Web Tokens express their lifetime as timestamps in seconds, so decoding a token and reading its exp claim tells you exactly when it expires. Cron-style schedules, cache headers, certificate validity and database created-at columns also commonly use epoch time.

When a token is rejected as expired, converting its exp value and comparing it with the current time is often the quickest way to see whether the problem is the token or a server clock that has drifted.

The Year 2038 problem

Older systems store the timestamp in a signed 32-bit integer, whose maximum value is 2,147,483,647 seconds. That moment is 03:14:07 UTC on 19 January 2038. One second later the value overflows and wraps to a large negative number, which would read as December 1901.

Modern 64-bit systems and current language runtimes are unaffected, but embedded devices, old file formats and legacy databases that still use 32-bit fields need attention before then.

Frequently asked questions

How do I get the current Unix timestamp?
In JavaScript use Math.floor(Date.now() / 1000) for seconds. In Python use int(time.time()). In a shell, date +%s prints the current time in seconds.
Can a Unix timestamp be negative?
Yes. Negative values represent moments before 1 January 1970. For example -86400 is 31 December 1969 at 00:00:00 UTC.
What format should I use when I want a human-readable date?
ISO 8601, for example 2026-01-01T00:00:00Z. It sorts correctly as text, includes the timezone, and is understood by virtually every language and database.

More guides