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.
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:
0= January 1, 1970, 00:00:00 UTC (the epoch)1000000000= September 9, 2001, 01:46:40 UTC1700000000= November 14, 2023, 22:13:20 UTC
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:
If your timestamp is already in milliseconds (13 digits):
Common formatting methods:
Watch out: getMonth() returns 0–11, not 1–12. November is 10. Always add 1 when displaying months.
Reverse — Date to Unix timestamp:
Python Conversion
Using the datetime module:
Format the date as a string:
Reverse — Date to Unix timestamp:
PHP Conversion
PHP's date() function handles Unix timestamps natively:
Bash / Command Line
On Linux and macOS, use the date command:
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:
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 2100 | 4102444800 |
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:
- JSON Formatter — beautify and validate API responses containing timestamps
- Base64 Encoder/Decoder — decode JWT tokens that contain Unix timestamps
- Regex Tester — match and extract timestamps from log files
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().