Home/Blog/Convert Unix Timestamp to Date in JavaScript
Dates · JavaScript

Convert Unix Timestamp to Date in JavaScript

4 min readUpdated January 2025Developer Tools
Unix timestamps show up everywhere in JavaScript — API responses, JWT claims, database records. Here's every method for converting them to readable dates, with timezone handling.

Unix Timestamp Converter

Convert any Unix timestamp to a readable date instantly. Supports seconds, milliseconds, and timezones.

Open Unix Timestamp Converter →

Basic conversion — new Date()

JavaScript's Date constructor accepts milliseconds since epoch. If your timestamp is in seconds (10 digits), multiply by 1000:

JavaScript
// Timestamp in SECONDS (10 digits)
const timestamp = 1704067200;
const date = new Date(timestamp * 1000);
console.log(date); // Mon Jan 01 2024 00:00:00 UTC

// Timestamp in MILLISECONDS (13 digits)
const tsMs = 1704067200000;
const date2 = new Date(tsMs);
console.log(date2); // same result
Quick check: 10-digit timestamp = seconds. 13-digit = milliseconds. Multiply seconds by 1000 before passing to new Date().

Formatting the date

JavaScript — formatting options
const date = new Date(1704067200 * 1000);

// ISO string (UTC)
date.toISOString();           // "2024-01-01T00:00:00.000Z"

// Locale string (user's timezone)
date.toLocaleDateString();    // "1/1/2024" (US format)
date.toLocaleTimeString();    // "12:00:00 AM"
date.toLocaleString();        // "1/1/2024, 12:00:00 AM"

// Custom format with Intl.DateTimeFormat
new Intl.DateTimeFormat('en-US', {
  year: 'numeric', month: 'long',
  day: 'numeric', hour: '2-digit', minute: '2-digit'
}).format(date);
// "January 1, 2024 at 12:00 AM"

Handling timezones correctly

Unix timestamps are always UTC. toLocaleDateString() converts to the user's local timezone automatically. To display in a specific timezone:

Specific timezone
const date = new Date(1704067200 * 1000);

// Display in a specific timezone
new Intl.DateTimeFormat('en-US', {
  timeZone: 'America/New_York',
  dateStyle: 'full',
  timeStyle: 'short'
}).format(date);
// "Sunday, December 31, 2023 at 7:00 PM"

// Display in UTC explicitly
new Intl.DateTimeFormat('en-US', {
  timeZone: 'UTC',
  dateStyle: 'medium',
  timeStyle: 'medium'
}).format(date);
// "Jan 1, 2024, 12:00:00 AM"

Convert date back to timestamp

JavaScript
// Current timestamp in milliseconds
Date.now();  // 1704067200000

// Current timestamp in seconds
Math.floor(Date.now() / 1000);  // 1704067200

// Specific date to timestamp
const d = new Date('2024-01-01T00:00:00Z');
Math.floor(d.getTime() / 1000);  // 1704067200

Check if a timestamp is expired (JWT use case)

JavaScript — check JWT exp
function isExpired(expTimestamp) {
  // exp is in seconds, Date.now() is in ms
  return Date.now() / 1000 > expTimestamp;
}

const payload = JSON.parse(atob(token.split('.')[1]));
if (isExpired(payload.exp)) {
  // Token expired — redirect to login
}

Frequently asked questions

Why does my date show the wrong day?
Almost always a timezone issue. A timestamp for "2024-01-01 00:00 UTC" will show as "December 31, 2023" in US timezones. Use toISOString() to see the UTC value, or explicitly pass timeZone: 'UTC' to Intl.DateTimeFormat.
Should I use moment.js for timestamp conversion?
Moment.js is no longer actively developed. For new projects, use the native Intl.DateTimeFormat API (shown above) or lightweight alternatives like date-fns or Temporal (the upcoming TC39 standard).
What is Date.now() vs new Date().getTime()?
They return the same value — milliseconds since epoch. Date.now() is slightly faster because it doesn't create a Date object.

Try it free — no sign-up needed

Runs entirely in your browser. Nothing uploaded, nothing stored.

Open Unix Timestamp Converter →

Related tools on tinybench.dev