To convert a Unix timestamp to a date, multiply the timestamp by 1000 to get milliseconds, then pass it to your language's Date constructor. In JavaScript: new Date(timestamp * 1000). In Python: datetime.fromtimestamp(timestamp). The result is the human-readable date and time.

This guide covers the conversion in JavaScript, Python, PHP, and Bash, explains the seconds vs milliseconds confusion, and shows how to handle timezones.

Quick Answer
Unix timestamp → Date
JavaScript: new Date(ts * 1000) for seconds
Python: datetime.fromtimestamp(ts)
PHP: date('Y-m-d H:i:s', ts)
Bash: date -d @ts

What Is a Unix Timestamp?

A Unix timestamp (also called epoch time) is the number of seconds that have passed since January 1, 1970, 00:00:00 UTC — a moment known as the Unix epoch. It's a universal way to represent time that is identical everywhere in the world, regardless of timezone.

For example:

Seconds vs Milliseconds — The #1 Confusion

Before converting anything, you need to know which unit your timestamp uses:

Digits Unit Example Used By
10 Seconds 1700000000 Unix, Linux, PHP, Python (default)
13 Milliseconds 1700000000000 JavaScript, Java, some APIs
16 Microseconds 1700000000000000 PostgreSQL, some databases

Rule of thumb: 10 digits = seconds. 13 digits = milliseconds. If you're in JavaScript, you almost always need to multiply by 1000 before passing to new Date().

Convert in JavaScript

JavaScript Conversion

JavaScript's Date constructor takes milliseconds, not seconds. So multiply by 1000:

// Timestamp in seconds const ts = 1700000000; // Convert to milliseconds and create Date const date = new Date(ts * 1000); console.log(date.toISOString()); // "2023-11-14T22:13:20.000Z" console.log(date.toLocaleString()); // "11/14/2023, 10:13:20 PM" (in your local timezone)

If your timestamp is already in milliseconds (13 digits):

const tsMs = 1700000000000; const date = new Date(tsMs); // no multiplication needed

Common formatting methods:

date.toISOString() // "2023-11-14T22:13:20.000Z" date.toUTCString() // "Tue, 14 Nov 2023 22:13:20 GMT" date.toLocaleString() // "11/14/2023, 10:13:20 PM" date.toLocaleDateString() // "11/14/2023" date.getFullYear() // 2023 date.getMonth() // 10 (0-indexed! add 1 for November) date.getDate() // 14

Watch out: getMonth() returns 0–11, not 1–12. November is 10. Always add 1 when displaying months.

Reverse — Date to Unix timestamp:

// Current time in seconds const now = Math.floor(Date.now() / 1000); // From a specific Date object const ts = Math.floor(new Date("2023-11-14").getTime() / 1000);

Python Conversion

Using the datetime module:

from datetime import datetime # Timestamp in seconds ts = 1700000000 # Local timezone dt = datetime.fromtimestamp(ts) print(dt) # 2023-11-14 22:13:20 (in your local timezone) # UTC timezone (recommended) dt_utc = datetime.utcfromtimestamp(ts) print(dt_utc) # 2023-11-14 22:13:20

Format the date as a string:

formatted = dt.strftime("%Y-%m-%d %H:%M:%S") print(formatted) # "2023-11-14 22:13:20"

Reverse — Date to Unix timestamp:

from datetime import datetime dt = datetime(2023, 11, 14, 22, 13, 20) ts = int(dt.timestamp()) print(ts) # 1700000000 # Current time import time now = int(time.time()) print(now)

PHP Conversion

PHP's date() function handles Unix timestamps natively:

<?php $ts = 1700000000; // Format the timestamp echo date('Y-m-d H:i:s', $ts); // "2023-11-14 22:13:20" (in server timezone) // UTC time echo gmdate('Y-m-d H:i:s', $ts); // "2023-11-14 22:13:20" // Reverse — current Unix timestamp echo time(); // From a date string echo strtotime('2023-11-14 22:13:20'); // 1700000000 ?>

Bash / Command Line

On Linux and macOS, use the date command:

# Timestamp to date (Linux) $ date -d @1700000000 Tue Nov 14 10:13:20 PM UTC 2023 # Custom format $ date -d @1700000000 +"%Y-%m-%d %H:%M:%S" 2023-11-14 22:13:20 # macOS uses -r instead of -d $ date -r 1700000000 +"%Y-%m-%d %H:%M:%S" # Current timestamp $ date +%s 1730000000

Timezone Handling — The #2 Confusion

Unix timestamps are always in UTC — but when you convert them, different methods show different timezones:

Method Timezone
new Date(ts).toISOString()UTC
new Date(ts).toLocaleString()Local (user's browser)
new Date(ts).toUTCString()UTC
Python datetime.fromtimestamp()Local
Python datetime.utcfromtimestamp()UTC
PHP date()Server timezone
PHP gmdate()UTC

Best practice: Store timestamps in UTC. Convert to local time only when displaying to a user. This avoids "why does my app show the wrong date?" bugs when users are in different timezones.

Manual Conversion (No Code)

If you want to understand what's happening under the hood, here's the manual math for converting timestamp 1700000000 to a date:

Manual Conversion
1. Start: Jan 1, 1970, 00:00:00 UTC
2. Add 1,700,000,000 seconds
3. 1,700,000,000 ÷ 86,400 (seconds per day) = 19,675.92 days
4. 19,675.92 days ≈ 53 years + 322 days
5. 1970 + 53 = 2023, day 322 of 2023
→ November 14, 2023 (approximately)

You don't need to do this manually — it's exactly what the code does — but understanding the math helps when debugging off-by-one-second errors.

Common Unix Timestamp Reference

Event Timestamp
Unix epoch (start)0
Y2K (Jan 1, 2000)946684800
9/11 attacks (Sep 11, 2001)1000000000
iPhone launch (Jun 29, 2007)1182988800
1 billion 2nd epoch (Nov 20, 2033)2000000000
Year 2038 problem (Jan 19, 2038)2147483647
Year 21004102444800

Debugging Common Errors

Error: "Invalid Date" in JavaScript

You probably forgot to multiply by 1000. If your timestamp is 10 digits, multiply. If it's 13 digits, don't.

Error: The date is off by ~50 years

You're treating a seconds timestamp as milliseconds, or vice versa. A date from 1970 usually means you forgot ×1000. A date from 2050+ usually means you multiplied something already in milliseconds.

Error: The time is off by a few hours

Timezone mismatch. Unix timestamps are UTC. toLocaleString() shows local time. Use toISOString() or toUTCString() for consistent UTC output.

Error: The date is off by 1 day

Timezone edge case. A timestamp near midnight UTC may show the previous day in a timezone behind UTC (like US timezones). Always compute in UTC when the exact day matters.

The Year 2038 Problem

Many older systems store Unix time as a 32-bit signed integer, which maxes out at 2,147,483,647 — the number of seconds in 68 years, 1 month, and 19 days from 1970. That moment arrives on January 19, 2038, at 03:14:07 UTC.

When that happens, affected systems will overflow and interpret the timestamp as 1901. The fix — already deployed on all modern 64-bit systems — is to store time as a 64-bit integer, which will last for roughly 292 billion years.

Legacy warning: If you maintain embedded systems, old databases, or any 32-bit system, plan for the year 2038 migration now. Modern web apps using 64-bit JavaScript are not affected.

Skip the Code — Use a Converter

Our free Unix Timestamp Converter does all of this in your browser. Paste any timestamp (seconds or milliseconds) and get the date in UTC, ISO 8601, local time, and multiple other formats. It also works in reverse.

⏱️ Free Unix Timestamp Converter

Convert epoch to date and back, with multiple formats and batch support.

Open Timestamp Converter →

Related Developer Tools

Working with timestamps usually means you're also handling other data formats. These free tools pair well:

🛠️ Developer Tools

Free in-browser utilities for developers.

Browse All Tools →

Frequently Asked Questions

How do I convert a Unix timestamp to a date?

In JavaScript: new Date(timestamp * 1000) if the timestamp is in seconds, or new Date(timestamp) if it's in milliseconds. In Python: datetime.fromtimestamp(timestamp).

Is Unix time in seconds or milliseconds?

Unix timestamps are traditionally in seconds (10 digits). JavaScript uses milliseconds (13 digits). To convert: if the number has 10 digits, it's seconds; if it has 13 digits, it's milliseconds. Multiply seconds by 1000 to get milliseconds.

What is the Unix epoch?

The Unix epoch is January 1, 1970, 00:00:00 UTC. Every Unix timestamp counts the number of seconds since that moment. Timestamp 0 = Jan 1, 1970.

Why does my converted timestamp look wrong?

The most common causes are: (1) using seconds when the value is in milliseconds — multiply by 1000; (2) timezone differences — Unix time is UTC but your browser may show local time; (3) JavaScript's getMonth() returns 0-11 instead of 1-12, so remember to add 1.

Does Unix time account for leap seconds?

No. Unix time ignores leap seconds. Each day is treated as exactly 86,400 seconds, even though a solar day can be slightly longer. This makes Unix time simple but not astronomically exact.

What is the Year 2038 problem?

On January 19, 2038 at 03:14:07 UTC, 32-bit signed integers used by older systems will overflow, causing timestamps to wrap around to 1901. Modern 64-bit systems are not affected.

How do I get the current Unix timestamp?

JavaScript: Math.floor(Date.now() / 1000). Python: int(time.time()). PHP: time(). Bash: date +%s.

Can I convert a Unix timestamp back to a date?

Yes. That's the reverse direction: use our free timestamp converter, or in JavaScript: new Date(ts * 1000).toISOString().