env.dev

Unix Timestamps Explained

What epoch time is, why it is used, the Y2K38 problem, and how to convert in different languages.

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 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.

Getting the Current 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)
EXTRACT(EPOCH FROM NOW())::BIGINT
SQL (MySQL)
UNIX_TIMESTAMP()

Converting a 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().

Useful 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)

The Year 2038 Problem (Y2K38)

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.

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