env.dev

Unix Timestamps Explained

What Unix epoch time is, why it is used, how the Y2K38 problem threatens 32-bit systems, and how to generate and convert timestamps across languages.

Last updated:

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?

JavaScript
Math.floor(Date.now() / 1000)
Python
import time
int(time.time())
Bash
date +%s
Go
time.Now().Unix()
Rust
SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs()
SQL (PostgreSQL)
SELECT EXTRACT(EPOCH FROM NOW())::BIGINT;
SQL (MySQL)
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?

JavaScript
new Date(timestamp * 1000).toISOString()
Python
datetime.utcfromtimestamp(timestamp)
Go
time.Unix(timestamp, 0).UTC()
Rust
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?

TimestampDate (UTC)
0Thu Jan 01 1970 00:00:00
1000000000Sat Sep 09 2001 01:46:40
1234567890Fri Feb 13 2009 23:31:30
1700000000Wed Nov 15 2023 00:13:20
2000000000Wed May 18 2033 03:33:20
2147483647Tue 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, while date +%s, Python's time.time(), and Go's time.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 of datetime.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 int32 overflows in 2038, but unsigned uint32 only 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

Convert between Unix timestamps and human-readable dates with the Unix Timestamp Converter tool.

Was this helpful?

Frequently Asked Questions

What is Unix epoch time?

Unix epoch time is the number of seconds elapsed since January 1, 1970 00:00:00 UTC. It provides a simple, timezone-independent way to represent a point in time. Most programming languages and databases support it natively.

What is the Y2038 problem?

The Y2038 problem occurs because many systems store Unix timestamps as a signed 32-bit integer, which overflows on January 19, 2038 at 03:14:07 UTC. Modern systems use 64-bit integers, extending the range billions of years into the future.

Are Unix timestamps in seconds or milliseconds?

Traditional Unix timestamps are in seconds. However, JavaScript (Date.now()) and some APIs use milliseconds. Java also uses milliseconds by default. Always check the documentation — divide by 1000 if you get a 13-digit timestamp.

How do I detect if a timestamp is in seconds or milliseconds?

10-digit numbers are seconds (valid through the year 2286); 13-digit numbers are milliseconds. A quick programmatic check is Math.log10(ts) >= 12 means milliseconds. JavaScript Date.now() always returns milliseconds; most other language standard libraries (Python time.time(), Go time.Now().Unix(), date +%s) return seconds.

Stay up to date

Get notified about new guides, tools, and cheatsheets.