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.

Current Unix time

Timestamp → Date

UTC
Local (your timezone)
ISO 8601
Relative

Date → Timestamp

Seconds
Milliseconds

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.

DigitsUnitExampleRange it covers
10Seconds17162390222001–2286
13Milliseconds17162390220002001–2286
16Microseconds1716239022000000Used by Python's time.time_ns()/1000
19Nanoseconds1716239022000000000Used 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?

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

Notable Unix timestamps

UTC date / timeUnix timestampNotes
1969-12-31 23:59:59-1One second before the epoch
1970-01-01 00:00:000The Unix epoch — the moment all Unix timestamps measure from
2000-01-01 00:00:00946684800Start of the year 2000
2001-09-09 01:46:401000000000One billion seconds since the epoch
2009-02-13 23:31:301234567890Often used as a test or fixture value
2017-07-14 02:40:0015000000001.5 billion
2020-01-01 00:00:001577836800Start of 2020
2023-11-14 22:13:2017000000001.7 billion
2024-01-01 00:00:001704067200Start of 2024
2025-01-01 00:00:001735689600Start of 2025
2026-01-01 00:00:001767225600Start of 2026
2033-05-18 03:33:202000000000Two billion
2038-01-19 03:14:072147483647Y2K38 — the last 32-bit signed integer
2106-02-07 06:28:154294967295Last 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.