A Unix timestamp (also called epoch time) is the number of seconds that have elapsed since 00:00:00 UTC on January 1, 1970 — the Unix epoch. It is the universal language for storing and comparing points in time in software systems.
Why use Unix epoch time?
- Time zone independent. A Unix timestamp represents the same instant everywhere on Earth. Display it in any timezone later.
- Simple arithmetic. Subtract two timestamps to get duration in seconds. Compare them with a single integer comparison.
- Compact. A 32-bit integer can represent dates across 136 years. A 64-bit integer handles billions of years.
- Universal. Every programming language and database supports Unix timestamps natively, which makes them the natural format for scheduled jobs — see the cron expression guide for how schedulers consume them.
How do you get the current Unix timestamp?
Math.floor(Date.now() / 1000)import time
int(time.time())date +%stime.Now().Unix()SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs()SELECT EXTRACT(EPOCH FROM NOW())::BIGINT;SELECT UNIX_TIMESTAMP();For more PostgreSQL date and time helpers, see the PostgreSQL cheat sheet.
How do you convert a Unix timestamp to a date?
new Date(timestamp * 1000).toISOString()datetime.utcfromtimestamp(timestamp)time.Unix(timestamp, 0).UTC()DateTime::from_timestamp(timestamp, 0)Note: JavaScript's Date uses milliseconds, not seconds. Multiply by 1000 when converting a Unix timestamp, and divide by 1000 when creating one from Date.now().
What are common Unix timestamp reference points?
| Timestamp | Date (UTC) |
|---|---|
| 0 | Thu Jan 01 1970 00:00:00 |
| 1000000000 | Sat Sep 09 2001 01:46:40 |
| 1234567890 | Fri Feb 13 2009 23:31:30 |
| 1700000000 | Wed Nov 15 2023 00:13:20 |
| 2000000000 | Wed May 18 2033 03:33:20 |
| 2147483647 | Tue Jan 19 2038 03:14:07 (max 32-bit) |
What is the Year 2038 (Y2K38) problem?
32-bit signed integers overflow on January 19, 2038 at 03:14:07 UTC (timestamp 2147483647). Systems storing timestamps in int32 will wrap to a negative number, representing dates in 1901. The fix is to use 64-bit integers — which can represent dates hundreds of billions of years into the future. Most modern systems already use 64-bit timestamps.
What are common Unix timestamp pitfalls?
- Milliseconds vs seconds in JavaScript.
Date.now()returns milliseconds, whiledate +%s, Python'stime.time(), and Go'stime.Now().Unix()return seconds. Mixing the two produces dates that are off by a factor of 1000 — usually showing as the year 1970 or far in the future. - Treating epoch as local time. Unix timestamps are always UTC. Converting one with a local-time API (e.g.
datetime.fromtimestamp()instead ofdatetime.utcfromtimestamp()) silently shifts the value by your machine's offset, which breaks reproducibility across servers and CI runners. - Excel auto-converting timestamps. Pasting a 10-digit timestamp into Excel can trigger automatic date detection or scientific-notation rounding, corrupting the value. Format the column as Text before pasting, or prefix with an apostrophe.
- Signed vs unsigned 32-bit overflow. Signed
int32overflows in 2038, but unsigneduint32only reaches its limit in 2106. Some legacy file formats and embedded systems use one or the other — verify before assuming a deadline. - Leap seconds are not represented. Unix time pretends every day has exactly 86400 seconds. Real UTC inserts leap seconds, so two Unix timestamps one second apart can represent the same wall-clock instant during a leap second. Use a monotonic clock for measuring durations.
References
- Wikipedia — Unix time
- RFC 3339 — Date and Time on the Internet: Timestamps
- EpochConverter — reference table and converter
- Wikipedia — Year 2038 problem
- Linux man pages —
time(2)
Convert between Unix timestamps and human-readable dates with the Unix Timestamp Converter tool.