Vaultools
Menu

Unix timestamp

A Unix timestamp is the number of seconds that have passed since 00:00:00 UTC on 1 January 1970, the Unix epoch. It is a single number that identifies a moment in time regardless of time zone, which makes it easy to store, sort and compare.

The basics

Unix time counts seconds from the epoch and ignores leap seconds, so every day is exactly 86,400 seconds. A few reference points:

TimestampMoment (UTC)
01970-01-01T00:00:00Z
17000000002023-11-14T22:13:20Z
21474836472038-01-19T03:14:07Z

Timestamps before 1970 are negative. A timestamp carries no time zone. It is always UTC, and the zone only matters when you display it.

Seconds versus milliseconds

Different systems use different units, and mixing them up is the most common time bug.

If a converted date lands in January 1970, you passed milliseconds to something expecting seconds. If it lands tens of thousands of years in the future, you did the opposite.

Converting in common languages

date -u -d @1700000000                                   # GNU date
date -u -r 1700000000                                    # macOS / BSD date
new Date(1700000000 * 1000).toISOString()                // JavaScript
datetime.fromtimestamp(1700000000, tz=timezone.utc)      # Python

The output as text is usually an ISO 8601 / RFC 3339 string.

The Year 2038 problem

A signed 32-bit integer tops out at 2147483647, which is 03:14:07 UTC on 19 January 2038. Systems still storing timestamps in 32 bits will overflow at that moment. Modern platforms use 64-bit values, which are good for billions of years, but old embedded devices, file formats and database columns can still be affected.

Common pitfalls

References

Ads on this page

Non-personalized ads help keep Vaultools free — Google decides where they appear on the page.

Go Pro to remove them →