Blog
Wild & Free Tools

Convert Unix Timestamp to Date in JavaScript — Every Method That Actually Works

Last updated: April 2026 7 min read

Table of Contents

  1. Unix Timestamp to Date
  2. Date to Unix Timestamp
  3. Timezones and ISO 8601
  4. Common Mistakes
  5. Frequently Asked Questions

JavaScript handles Unix timestamps differently than every other language — and it trips up developers constantly. The Date object expects milliseconds, but most APIs return seconds. Mix them up and you get dates in the year 1970 or somewhere in the year 51000.

This guide walks through every Unix timestamp conversion you will need in JavaScript: timestamp to Date, Date to timestamp, with timezones, in milliseconds, in seconds, formatted, and as ISO 8601. Every snippet is copy-paste ready.

If you just need a quick conversion without writing code, the free Unix timestamp converter handles seconds and milliseconds automatically.

Convert a Unix Timestamp to a Date in JavaScript

The fundamental rule: JavaScript Date expects milliseconds, not seconds. A standard Unix timestamp is in seconds. So you have to multiply by 1000 first.

// Unix timestamp in seconds (10 digits)
const unixSeconds = 1711000000;
const date = new Date(unixSeconds * 1000);
console.log(date); // 2024-03-21T07:46:40.000Z

// Already in milliseconds (13 digits)
const unixMs = 1711000000000;
const date2 = new Date(unixMs);
console.log(date2); // 2024-03-21T07:46:40.000Z

How to tell which one you have: a 10-digit number is seconds, a 13-digit number is milliseconds. Anything between 1971 and roughly the year 2286 falls in those ranges. If your number is much shorter or longer, something is wrong.

Format the result as a readable date

The raw Date object prints in ISO format. To get a human-friendly format, use the locale methods:

const date = new Date(1711000000 * 1000);
date.toLocaleString();      // "3/21/2024, 3:46:40 AM"
date.toDateString();        // "Thu Mar 21 2024"
date.toISOString();         // "2024-03-21T07:46:40.000Z"
date.toLocaleDateString();  // "3/21/2024"

For custom formats (yyyy-mm-dd, dd/mm/yyyy, etc.), use date-fns or Day.js — both are 2KB libraries that handle every format string you could want without pulling in moment.js.

Convert a Date to a Unix Timestamp in JavaScript

Going the other direction is even simpler. Date.getTime() returns milliseconds since epoch. Divide by 1000 and floor it to get the standard Unix timestamp in seconds.

// Current time as Unix timestamp (seconds)
const nowSeconds = Math.floor(Date.now() / 1000);
console.log(nowSeconds); // e.g. 1744070000

// Current time in milliseconds
const nowMs = Date.now();

// Specific date string
const date = new Date('2026-04-08T12:00:00Z');
const timestamp = Math.floor(date.getTime() / 1000);

Why Math.floor and not Math.round? Because Unix timestamps are integers — fractional seconds are not part of the standard. Most APIs that accept timestamps will reject decimals or silently truncate them, which causes off-by-one bugs that are nearly impossible to debug.

Get current Unix timestamp — the shortest version

// One-liner — current Unix timestamp in seconds
const ts = (Date.now() / 1000) | 0;

The | 0 trick is a faster bitwise floor than Math.floor for positive numbers. Both work — pick whichever you find more readable.

Sell Custom Apparel — We Handle Printing & Free Shipping

Handling Timezones When Converting Timestamps

Unix timestamps are always in UTC. They have no timezone — they are just a count of seconds since 1970-01-01 UTC. Timezone confusion happens when you display the result.

const date = new Date(1711000000 * 1000);

// Display in user's local timezone (browser default)
date.toLocaleString();
// "3/21/2024, 3:46:40 AM" — local time

// Display in a specific timezone
date.toLocaleString('en-US', { timeZone: 'America/New_York' });
// "3/21/2024, 3:46:40 AM"

date.toLocaleString('en-US', { timeZone: 'Asia/Tokyo' });
// "3/21/2024, 4:46:40 PM"

The timestamp itself never changes. The display changes. This is the single most important concept in working with Unix time — store and transmit timestamps in UTC always, convert to local time only at the display layer.

ISO 8601 format

If you need to send a timestamp as a string (REST APIs, JSON payloads, log files), ISO 8601 is the standard format. JavaScript Date includes it built in:

new Date(1711000000 * 1000).toISOString();
// "2024-03-21T07:46:40.000Z"

The "Z" at the end means UTC. Almost every backend language can parse this format directly without configuration.

JavaScript Timestamp Conversion Mistakes That Cause Real Bugs

Five mistakes that I have seen ship to production. All of them are easy to make and hard to spot in code review.

1. Forgetting to multiply by 1000

You pass a seconds-based Unix timestamp directly to new Date(ts) without multiplying. The result is a date in January 1970 — specifically, 1711000000 milliseconds is January 20, 1970. Looks like a Date object, prints like one, but the year is completely wrong.

2. Mixing seconds and milliseconds in the same codebase

Backend returns timestamps in seconds, frontend stores them in milliseconds, comparisons fail silently. Pick one unit and stick to it across the entire stack. Most teams choose milliseconds because that is what JavaScript wants natively.

3. Using parseInt on a string timestamp without a radix

parseInt("1711000000") works, but parseInt("0x1711000000") parses as hex. Always use Number() or parseInt(str, 10) for safety.

4. Treating Date as immutable

Date objects are mutable. date.setHours(0) modifies the original. If you pass a Date to a function and it modifies it, you have a bug nobody will catch until production. Clone first: new Date(originalDate).

5. Trusting the user's clock

Browser Date.now() reads the user's system clock. If they have it set wrong, your timestamps are wrong. For anything where time matters (auth tokens, audit logs, time-based gates), get the timestamp from your server, not the client.

If you need to verify a timestamp value quickly without writing code, paste it into the free Unix timestamp converter — it auto-detects seconds vs milliseconds and shows both UTC and human-readable output.

Try It Free — No Signup Required

Runs 100% in your browser. No data is collected, stored, or sent anywhere.

Open Free Unix Timestamp Converter

Frequently Asked Questions

How do I convert a Unix timestamp to a JavaScript Date?

Multiply the timestamp by 1000 (because JavaScript expects milliseconds) and pass it to new Date(). Example: new Date(1711000000 * 1000) gives March 21, 2024. If your timestamp is already 13 digits (milliseconds), skip the multiplication.

Why is my JavaScript Date showing 1970?

You almost certainly forgot to multiply your seconds-based timestamp by 1000. JavaScript Date expects milliseconds. A 10-digit timestamp passed directly is interpreted as a few minutes after the Unix epoch (January 1970), not the actual date.

How do I get the current Unix timestamp in JavaScript?

Math.floor(Date.now() / 1000) gives you the current Unix timestamp in seconds. Date.now() alone gives milliseconds. Both are based on the system clock at the moment the code runs.

Does JavaScript store dates in UTC or local time?

Internally, JavaScript Date stores the value as milliseconds since the Unix epoch in UTC. Display methods like toString() and toLocaleString() apply the user's local timezone. The underlying value never has a timezone — only the display does.

How do I convert a timestamp to a specific timezone in JavaScript?

Use toLocaleString with the timeZone option: date.toLocaleString("en-US", { timeZone: "America/New_York" }). This works in modern browsers and Node.js. The timestamp itself does not change — only how it is rendered.

What is the difference between getTime() and valueOf() on a Date?

They return the exact same value: milliseconds since the Unix epoch. valueOf() is what JavaScript calls automatically when you compare dates with operators like < or >. getTime() is the same thing called explicitly.

Launch Your Own Clothing Brand — No Inventory, No Risk