What is Unix time?
Unix time counts the seconds since 00:00:00 UTC on 1 January 1970, the “Unix epoch”. Because it’s just a number with no time zone, it’s the standard way to store and exchange moments in time: in API responses, databases, JWT tokens (exp, iat), log files and HTTP caching.
Seconds, milliseconds, microseconds or nanoseconds?
| Unit | Digits today | Example | Commonly used by |
|---|---|---|---|
| Seconds | 10 | 1792800000 | Unix, PHP, Python’s time(), most APIs, JWTs |
| Milliseconds | 13 | 1792800000000 | JavaScript (Date.now()), Java, many JSON APIs |
| Microseconds | 16 | 1792800000000000 | PostgreSQL internals, some logging systems |
| Nanoseconds | 19 | 1792800000000000000 | Go (UnixNano), Python’s time_ns(), tracing tools |
Mixing these up is the most common timestamp bug: a seconds value read as milliseconds lands in January 1970, and a milliseconds value read as seconds lands tens of thousands of years in the future.
Notable Unix timestamps
| Timestamp | Date | Why it matters |
|---|---|---|
0 | 1970-01-01 00:00:00 UTC | The Unix epoch |
1000000000 | 2001-09-09 01:46:40 UTC | The first billion seconds |
1234567890 | 2009-02-13 23:31:30 UTC | Celebrated by developers worldwide |
2000000000 | 2033-05-18 03:33:20 UTC | Two billion seconds |
2147483647 | 2038-01-19 03:14:07 UTC | Largest signed 32-bit value: the Year 2038 problem |
4294967295 | 2106-02-07 06:28:15 UTC | Largest unsigned 32-bit value |
Get the current Unix timestamp in code
Math.floor(Date.now() / 1000); // seconds
Date.now(); // millisecondsimport time
int(time.time()) # seconds
time.time_ns() // 1_000_000 # milliseconds<?php
time(); // seconds
(int) (microtime(true) * 1000); // millisecondstime.Now().Unix() // seconds
time.Now().UnixMilli() // millisecondsInstant.now().getEpochSecond(); // seconds
System.currentTimeMillis(); // millisecondsDateTimeOffset.UtcNow.ToUnixTimeSeconds(); // seconds
DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); // millisecondsTime.now.to_i # seconds
(Time.now.to_f * 1000).to_i # milliseconds-- PostgreSQL
SELECT EXTRACT(EPOCH FROM now())::bigint;
-- MySQL
SELECT UNIX_TIMESTAMP();date +%s # seconds
date +%s%3N # milliseconds (GNU date)Convert a Unix timestamp to a date in code
new Date(1792800000 * 1000).toISOString();
// '2026-10-24T00:00:00.000Z'from datetime import datetime, timezone
datetime.fromtimestamp(1792800000, tz=timezone.utc).isoformat()
# '2026-10-24T00:00:00+00:00'<?php
gmdate('Y-m-d\TH:i:s\Z', 1792800000);
// '2026-10-24T00:00:00Z'time.Unix(1792800000, 0).UTC().Format(time.RFC3339)
// "2026-10-24T00:00:00Z"Instant.ofEpochSecond(1792800000L).toString();
// "2026-10-24T00:00:00Z"DateTimeOffset.FromUnixTimeSeconds(1792800000).UtcDateTime;require 'time'
Time.at(1792800000).utc.iso8601
# "2026-10-24T00:00:00Z"-- PostgreSQL
SELECT to_timestamp(1792800000);
-- MySQL
SELECT FROM_UNIXTIME(1792800000);date -u -d @1792800000 # GNU/Linux
date -u -r 1792800000 # macOS/BSDTime zones: store UTC, convert when you display
A timestamp is the same everywhere, so store and send timestamps (or ISO 8601 strings in UTC) and convert to a local time zone only when showing a date to a person. Use IANA zone names like Africa/Lagos or America/New_York rather than fixed offsets: offsets change with daylight saving time, and the converter above accounts for that automatically.
Many public APIs return Unix time. Weather APIs like Open-Meteo can return it for forecast hours, and crypto and stock APIs use it for price history. Find more in the API directory.