Convert Unix timestamps to dates and back — seconds, milliseconds, any timezone
// Current timestamp
Math.floor(Date.now() / 1000) // seconds
Date.now() // ms
// Timestamp to Date
new Date(1717500000 * 1000)
new Date(1717500000000) // ms
// Date to timestamp
Math.floor(new Date('2024-06-04').getTime() / 1000)
import datetime, time
# Current timestamp
int(time.time())
time.time() # float seconds
# Timestamp to datetime
datetime.datetime.fromtimestamp(1717500000)
datetime.datetime.utcfromtimestamp(1717500000)
# Date to timestamp
datetime.datetime(2024,6,4).timestamp()
-- PostgreSQL
SELECT to_timestamp(1717500000);
SELECT EXTRACT(EPOCH FROM NOW());
-- MySQL
SELECT FROM_UNIXTIME(1717500000);
SELECT UNIX_TIMESTAMP(NOW());
-- SQLite
SELECT datetime(1717500000, 'unixepoch');
SELECT strftime('%s', 'now');
// Go
time.Unix(1717500000, 0)
time.Now().Unix()
// PHP
date('Y-m-d', 1717500000);
strtotime('2024-06-04');
// Java
Instant.ofEpochSecond(1717500000L)
Instant.now().getEpochSecond()
A Unix timestamp is the number of seconds that have elapsed since the Unix epoch: January 1, 1970, 00:00:00 UTC. It is a universal, timezone-independent way to represent any moment in time. The current timestamp is roughly 1.7 billion seconds. Timestamps are used in virtually every programming language, database, API, and log file because they avoid all ambiguity about timezones, date formats, and locale differences.
Unix timestamps traditionally measure seconds (10 digits, e.g. 1717500000). JavaScript's Date.now() returns milliseconds (13 digits, e.g. 1717500000000). This tool auto-detects based on the number of digits: 10 digits = seconds, 13 digits = milliseconds. If your timestamp is 13 digits, divide by 1000 to get seconds.
The "Year 2038 problem" affects systems that store Unix timestamps as a 32-bit signed integer. The maximum value is 2,147,483,647, which corresponds to January 19, 2038, 03:14:07 UTC. After that, the value overflows to a negative number. Modern 64-bit systems are not affected — a 64-bit timestamp can represent dates up to year 292 billion. JavaScript uses 64-bit floats and is safe. The issue mainly affects legacy C code and old database schemas.
January 1, 1970 was chosen as the epoch when Unix was developed at Bell Labs in the early 1970s. It was a recent, round date that made calculations convenient. The choice was somewhat arbitrary — the important thing was having a single, universally agreed starting point. That date is now permanently embedded in virtually every computer system on the planet.
For seconds: new Date(timestamp * 1000). For milliseconds: new Date(timestamp). To get the current timestamp in seconds: Math.floor(Date.now() / 1000). To convert a date string to timestamp: Math.floor(new Date('2024-06-04').getTime() / 1000).