What Is a Unix Timestamp?
A Unix timestamp (also called epoch time or POSIX time) is the number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC — known as the Unix epoch. It's a simple integer that represents any point in time, regardless of timezone.
For example, the timestamp 1709251200 represents March 1, 2024 at midnight UTC. Timestamps before the epoch are negative numbers.
Why Use Unix Timestamps?
- Timezone-agnostic — A single number represents the same moment everywhere
- Easy to compare — Simple integer comparison for sorting and filtering
- Compact storage — An integer uses less space than a date string
- Language-agnostic — Every programming language can parse and generate them
- Database-friendly — Efficient indexing and range queries
Converting Timestamps in Every Language
JavaScript
// Current timestamp (milliseconds)
const now = Date.now(); // 1709251200000
const nowSec = Math.floor(now / 1000); // 1709251200 // Timestamp to Date
const date = new Date(1709251200 * 1000);
console.log(date.toISOString()); // "2024-03-01T00:00:00.000Z" // Date to timestamp
const ts = Math.floor(new Date("2024-03-01").getTime() / 1000);Python
import time, datetime # Current timestamp
now = int(time.time()) # 1709251200 # Timestamp to datetime
dt = datetime.datetime.fromtimestamp(1709251200, tz=datetime.timezone.utc)
print(dt.isoformat()) # "2024-03-01T00:00:00+00:00" # Datetime to timestamp
ts = int(dt.timestamp())Other Languages
// Go
time.Now().Unix() // Rust
SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs() // PHP
time() // current timestamp
date('Y-m-d', 1709251200) // timestamp to date // SQL
SELECT EXTRACT(EPOCH FROM NOW()); -- PostgreSQL
SELECT UNIX_TIMESTAMP(); -- MySQLMilliseconds vs Seconds
A common bug source: JavaScript's Date.now() returns milliseconds (13 digits), while most other languages and APIs use seconds (10 digits). If you see a timestamp like 1709251200000, divide by 1000 before sending it to a backend.
The Year 2038 Problem
On January 19, 2038 at 03:14:07 UTC, 32-bit signed integer timestamps will overflow. Systems using 32-bit time_t will wrap to negative values (interpreted as December 1901). Most modern systems have migrated to 64-bit timestamps, which won't overflow for 292 billion years.
Timestamp Best Practices
- Store timestamps in UTC — convert to local time only at display time
- Use ISO 8601 strings for APIs and human-readable logs
- Use 64-bit integers for timestamp storage to avoid 2038 issues
- Always clarify whether a timestamp is in seconds or milliseconds in your API docs
- Use
TIMESTAMPTZin PostgreSQL instead of plainTIMESTAMP
Convert timestamps instantly with our Timestamp Converter or batch-process multiple values with the Epoch Batch Converter.