DevToolsForYou

Unix Timestamp Converter in JavaScript / Node.js — Code Examples

Unix Timestamp Converter in JavaScript / Node.jsUse the online tool →

A Unix timestamp is the number of seconds (or milliseconds) since 1 January 1970 00:00:00 UTC. Here is how to get the current timestamp, convert to a human-readable date, and parse date strings back to timestamps in each language.

JavaScript's Date object works in milliseconds. Divide by 1000 for Unix seconds. Use Intl.DateTimeFormat or date-fns for formatting.

JavaScript
// Current timestamp
const nowMs  = Date.now();             // milliseconds since epoch
const nowSec = Math.floor(Date.now() / 1000); // seconds since epoch

// Timestamp → Date object
const date = new Date(1700000000 * 1000); // multiply seconds by 1000
console.log(date.toISOString()); // 2023-11-14T22:13:20.000Z
console.log(date.toLocaleString("en-IN", { timeZone: "Asia/Kolkata" }));

// Date string → timestamp
const ts = new Date("2023-11-14T22:13:20Z").getTime() / 1000;
console.log(ts); // 1700000000

// Format a timestamp (Intl API — no library needed)
const fmt = new Intl.DateTimeFormat("en-US", {
  dateStyle: "full",
  timeStyle: "long",
  timeZone: "America/New_York",
});
console.log(fmt.format(new Date(1700000000 * 1000)));
Notes & gotchas
  • Date.now() returns milliseconds; most Unix APIs expect seconds — remember to divide or multiply by 1000.
  • new Date(seconds) is wrong — it interprets the value as milliseconds, giving a date in 1970.
  • Use Intl.DateTimeFormat for timezone-aware formatting without a library.
Try it in your browser

Need to epoch/unix converter without writing code? The Unix Timestamp Converter runs entirely in your browser — paste your input and get the result instantly. No signup, no install, no data sent to a server.

Open Epoch/Unix Converter
Unix Timestamp Converter in other languages