Understanding Unix Timestamps
3 min read · Published
Table of contents
A Unix timestamp (also called epoch time or POSIX time) is the number of seconds that have elapsed since 00:00:00 UTC on 1 January 1970, not counting leap seconds. It is the simplest unambiguous way to store a moment in time, which is why databases, logs, APIs and JWTs use it everywhere.
Convert any value instantly with the Timestamp Converter.
A few reference points
| Timestamp | UTC date |
|---|---|
0 |
1970-01-01 00:00:00 |
1000000000 |
2001-09-09 01:46:40 |
1700000000 |
2023-11-14 22:13:20 |
2147483647 |
2038-01-19 03:14:07 |
Seconds versus milliseconds
Traditional Unix time counts seconds. JavaScript's Date.now(), Java's System.currentTimeMillis() and many web APIs use milliseconds.
| Unit | Example (same moment) | Digits today |
|---|---|---|
| Seconds | 1700000000 |
10 |
| Milliseconds | 1700000000000 |
13 |
Mixing them up is the most common timestamp bug: passing seconds to new Date() gives a date in January 1970.
new Date(1700000000); // 1970-01-20 (wrong: that is seconds!)
new Date(1700000000 * 1000); // 2023-11-14T22:13:20.000Z
Timestamps have no time zone
A timestamp identifies one instant worldwide. A time zone only matters when you display it:
const d = new Date(1700000000 * 1000);
d.toISOString(); // "2023-11-14T22:13:20.000Z" (UTC)
d.toLocaleString('en-US', { timeZone: 'America/New_York' }); // 11/14/2023, 5:13:20 PM
d.toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' }); // 15/11/2023, 3:43:20 am
Best practice: store and transmit UTC (timestamps or ISO 8601 strings ending in Z), and convert to local time only in the user interface.
ISO 8601
The human-readable standard for dates is ISO 8601: 2023-11-14T22:13:20Z. The T separates date from time and the trailing Z means UTC; an offset such as +05:30 expresses a local time. It sorts correctly as text and every language can parse it.
Converting in code
// JavaScript
Math.floor(Date.now() / 1000); // now, seconds
new Date(ts * 1000).toISOString(); // seconds -> ISO
Date.parse('2023-11-14T22:13:20Z') / 1000; // ISO -> seconds
import time, datetime
int(time.time()) # now, seconds
datetime.datetime.fromtimestamp(1700000000, datetime.timezone.utc)
datetime.datetime(2023, 11, 14, 22, 13, 20, tzinfo=datetime.timezone.utc).timestamp()
-- PostgreSQL
SELECT to_timestamp(1700000000);
SELECT extract(epoch FROM now());
-- MySQL
SELECT FROM_UNIXTIME(1700000000);
SELECT UNIX_TIMESTAMP();
date -u -d @1700000000 # GNU/Linux
date -u -r 1700000000 # macOS / BSD
date +%s # now
The Year 2038 problem
Many older systems store Unix time in a signed 32-bit integer, whose maximum value is 2,147,483,647, corresponding to 03:14:07 UTC on 19 January 2038. One second later the value overflows to a negative number and the clock jumps to 1901. Modern 64-bit systems and JavaScript (which uses 64-bit floating point) are not affected, but embedded devices, old file formats and some databases columns might be. Use 64-bit integers for new schemas.
Leap seconds and "smearing"
Unix time pretends every day has exactly 86,400 seconds. Real UTC occasionally inserts a leap second; operating systems either repeat a second or "smear" it over hours. For almost all application code you can ignore this, but do not use wall-clock time to measure precise durations. Use a monotonic clock (performance.now(), time.monotonic()).
Practical advice
- Name units in your API:
created_at_msor document seconds clearly. - Never store local times without an offset or zone.
- Daylight saving makes local days 23 or 25 hours long; do date arithmetic in UTC.
- Compare instants as numbers, not formatted strings in different zones.
- JWT claims
exp,iatandnbfare in seconds; our JWT Decoder converts them. - Cron schedules run in the server's time zone; verify with the Cron Expression Explainer.
- Timestamps are plain integers, so you can inspect their bits with the Number Base Converter.
For how APIs should represent time, see REST API Basics.
Related tools
Timestamp Converter
Convert Unix timestamps to dates and back, in UTC and local time.
JWT Decoder
Decode JWT header, payload and expiry. Never leaves your browser.
Cron Expression Explainer
Translate cron expressions into plain English.
FAQ
What date is timestamp 0?
1970-01-01T00:00:00Z, the Unix epoch.
Do Unix timestamps have time zones?
No. They count seconds since the epoch in UTC. Time zones only matter when you display the value.
How do I tell seconds from milliseconds?
Current-era timestamps have 10 digits in seconds and 13 digits in milliseconds.
Keep reading
- JWT Explained for Beginners
A beginner-friendly explanation of JSON Web Tokens: structure, claims, signing, expiry, and the security mistakes to avoid.
- REST API Basics
Understand REST APIs: resources, HTTP methods, status codes, JSON payloads, idempotency, pagination, versioning and authentication basics.