Unix Timestamp Converter
Convert Unix epoch timestamps (seconds or milliseconds) to human-readable dates, and convert any date back to a timestamp. Snippets below show the canonical idiom in JavaScript, Python, SQL, Java, Go, PHP, Bash, and Excel.
Timestamp → Date
Date → Timestamp
Seconds or milliseconds? How to tell
The most common Unix timestamp bug is mistaking seconds for milliseconds (or vice versa) and being off by a factor of 1000. The fix is simple once you know to look for it.
The digit-count rule
Today's timestamps in seconds are 10 digits long. The same instant in milliseconds is 13 digits. As long as the date is between 2001 and 2286, the digit count tells you the unit unambiguously.
| Digits | Unit | Example | Range it covers |
|---|---|---|---|
| 10 | Seconds | 1716239022 | 2001–2286 |
| 13 | Milliseconds | 1716239022000 | 2001–2286 |
| 16 | Microseconds | 1716239022000000 | Used by Python's time.time_ns()/1000 |
| 19 | Nanoseconds | 1716239022000000000 | Used by Go's time.Time.UnixNano() |
Quick conversion
Multiply seconds by 1000 to get milliseconds. Divide milliseconds by 1000 (and floor) to get seconds. The converter above auto-detects based on magnitude — anything ≥ 1012 is treated as milliseconds.
Which language uses which by default?
- Seconds: Python (
time.time()), Ruby (Time.now.to_i), Go (time.Now().Unix()), Bash (date +%s), MySQLUNIX_TIMESTAMP(), PostgreSQLEXTRACT(EPOCH FROM ...). - Milliseconds: JavaScript (
Date.now()), Java (System.currentTimeMillis()), Kotlin, the JVM ecosystem in general. - Both, depending on API call: Java's
java.time.Instant, .NET'sDateTimeOffset, Go'stime.Time(viaUnix,UnixMilli,UnixNano).
Convert Unix timestamps in any language
The canonical idiom for converting between Unix timestamps and dates in the languages most commonly searched.
JavaScript / TypeScript
JavaScript's Date uses milliseconds — multiply seconds by 1000 first.
// Unix timestamp (seconds) → Date
const date = new Date(1716239022 * 1000);
// Unix timestamp (milliseconds) → Date
const date = new Date(1716239022000);
// Current Unix timestamp (seconds)
const now = Math.floor(Date.now() / 1000);
// Date → Unix timestamp (seconds)
const ts = Math.floor(new Date('2024-05-20T00:00:00Z').getTime() / 1000);
Python
Always use tz=timezone.utc unless you specifically want local time.
from datetime import datetime, timezone import time # Unix timestamp → datetime (UTC) dt = datetime.fromtimestamp(1716239022, tz=timezone.utc) # Current Unix timestamp (seconds) now = int(time.time()) # datetime → Unix timestamp ts = int(datetime(2024, 5, 20, tzinfo=timezone.utc).timestamp())
SQL — PostgreSQL
-- Unix timestamp → timestamp with time zone SELECT to_timestamp(1716239022); -- Current Unix timestamp (seconds) SELECT EXTRACT(EPOCH FROM NOW())::BIGINT; -- Timestamp → Unix timestamp SELECT EXTRACT(EPOCH FROM TIMESTAMP '2024-05-20 00:00:00')::BIGINT;
SQL — MySQL
-- Unix timestamp → datetime
SELECT FROM_UNIXTIME(1716239022);
-- Current Unix timestamp (seconds)
SELECT UNIX_TIMESTAMP();
-- datetime → Unix timestamp
SELECT UNIX_TIMESTAMP('2024-05-20 00:00:00');
Java (java.time)
Use java.time from Java 8 onwards — the legacy Date class is broken in too many ways to recommend.
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
// Unix timestamp → Instant
Instant t = Instant.ofEpochSecond(1716239022L);
// Current Unix timestamp (seconds)
long now = Instant.now().getEpochSecond();
// ZonedDateTime → Unix timestamp
long ts = ZonedDateTime
.of(2024, 5, 20, 0, 0, 0, 0, ZoneOffset.UTC)
.toEpochSecond();
Go
import "time" // Unix timestamp → time.Time t := time.Unix(1716239022, 0) // Current Unix timestamp (seconds) now := time.Now().Unix() // time.Time → Unix timestamp ts := time.Date(2024, 5, 20, 0, 0, 0, 0, time.UTC).Unix()
PHP
// Unix timestamp → formatted date string
$date = date('Y-m-d H:i:s', 1716239022);
// Unix timestamp → DateTime object
$dt = (new DateTime())->setTimestamp(1716239022);
// Current Unix timestamp (seconds)
$now = time();
// Date string → Unix timestamp
$ts = strtotime('2024-05-20 UTC');
Bash / Shell
GNU and BSD date have different syntaxes — macOS ships BSD, most Linux distros ship GNU.
# Current Unix timestamp (any platform) date +%s # Unix timestamp → date (GNU / Linux) date -d @1716239022 # Unix timestamp → date (BSD / macOS) date -r 1716239022 # Date → Unix timestamp (GNU) date -d "2024-05-20" +%s # Date → Unix timestamp (BSD / macOS) date -j -f "%Y-%m-%d" "2024-05-20" +%s
Excel / Google Sheets
Spreadsheets store dates as days since 1899-12-30. Convert between that and the Unix epoch (1970-01-01) using these formulas, with the timestamp in cell A1:
' Unix timestamp (seconds) → Date — format the cell as a date afterwards =A1/86400 + DATE(1970,1,1) ' Date → Unix timestamp (seconds) =(A1 - DATE(1970,1,1)) * 86400
Common Unix timestamp gotchas
- Negative timestamps. Dates before 1970-01-01 produce negative numbers. Most systems accept them, but some databases and APIs (notably some MySQL versions and unsigned columns) do not.
- Leap seconds. The Unix timestamp definition technically excludes leap seconds, so it is not a strict count of SI seconds. For most applications the difference is invisible — leap seconds are smeared across a day at the OS level.
- Year 2038 (Y2K38). 32-bit signed timestamps overflow on January 19, 2038 at 03:14:07 UTC. 64-bit systems are unaffected; check that any embedded device or legacy database column uses at least a 64-bit (or unsigned 32-bit, which lasts until 2106) representation.
- Local time vs UTC. A Unix timestamp is always UTC by definition — it has no time-zone information attached. The conversions above generally let you pick which time zone to render the result in. Choose deliberately; the most common date bugs come from rendering UTC as local-without-conversion.
- ISO 8601 with offset ≠ Unix timestamp.
2024-05-20T15:00:00+02:00is unambiguous (it's a specific UTC instant) but it isn't a Unix timestamp. Convert via the language idioms above.
Notable Unix timestamps
| UTC date / time | Unix timestamp | Notes |
|---|---|---|
| 1969-12-31 23:59:59 | -1 | One second before the epoch |
| 1970-01-01 00:00:00 | 0 | The Unix epoch — the moment all Unix timestamps measure from |
| 2000-01-01 00:00:00 | 946684800 | Start of the year 2000 |
| 2001-09-09 01:46:40 | 1000000000 | One billion seconds since the epoch |
| 2009-02-13 23:31:30 | 1234567890 | Often used as a test or fixture value |
| 2017-07-14 02:40:00 | 1500000000 | 1.5 billion |
| 2020-01-01 00:00:00 | 1577836800 | Start of 2020 |
| 2023-11-14 22:13:20 | 1700000000 | 1.7 billion |
| 2024-01-01 00:00:00 | 1704067200 | Start of 2024 |
| 2025-01-01 00:00:00 | 1735689600 | Start of 2025 |
| 2026-01-01 00:00:00 | 1767225600 | Start of 2026 |
| 2033-05-18 03:33:20 | 2000000000 | Two billion |
| 2038-01-19 03:14:07 | 2147483647 | Y2K38 — the last 32-bit signed integer |
| 2106-02-07 06:28:15 | 4294967295 | Last 32-bit unsigned integer (buys ~68 more years) |
Frequently asked questions
How do I convert a Unix timestamp to a date in JavaScript?
JavaScript's Date works in milliseconds, so multiply the timestamp by 1000 first: new Date(1716239022 * 1000). To go the other way, Math.floor(Date.now() / 1000) gives you the current timestamp in seconds.
How do I convert a Unix timestamp to a date in Python?
Use datetime.fromtimestamp(ts, tz=timezone.utc) from the datetime module. Always pass an explicit tz — without it, Python interprets the result in the system's local time zone, which is a common source of bugs.
How do I convert a Unix timestamp in SQL?
In PostgreSQL, SELECT to_timestamp(1716239022) returns a timestamp with time zone. In MySQL, SELECT FROM_UNIXTIME(1716239022) returns a datetime. To go the other direction, use EXTRACT(EPOCH FROM ...) in Postgres or UNIX_TIMESTAMP(...) in MySQL.
What is a Unix timestamp?
A Unix timestamp is the number of seconds (or milliseconds) elapsed since January 1, 1970 at 00:00:00 UTC — the "Unix epoch." It is the dominant way of representing absolute time in computers because it is timezone-independent and easy to compare arithmetically.
How do I tell if a timestamp is in seconds or milliseconds?
Look at the number of digits. A 10-digit timestamp (like 1716239022) is seconds. A 13-digit timestamp (like 1716239022000) is milliseconds. The converter above auto-detects, but you can override the unit if needed.
What is the Year 2038 problem?
On 32-bit systems, signed Unix timestamps overflow on January 19, 2038 at 03:14:07 UTC. Modern 64-bit systems — which include essentially all servers, phones, and laptops since 2010 — use 64-bit timestamps and won't overflow for billions of years.