Convert Unix Timestamps in JavaScript (Seconds, ms & Timezones)
Passing a 10-digit backend Unix timestamp straight into new Date(1764892800) produces January 21, 1970 instead of today. That bug happens because JavaScript Date functions always work in 13-digit milliseconds, never 10-digit seconds.
Get the Current Unix Timestamp in JavaScript
Use Date.now() to get the current time in milliseconds, or divide by 1,000 and round down with Math.floor() for standard Unix seconds.
// Current Unix timestamp in milliseconds (13 digits)
const nowMs = Date.now();
// Current Unix timestamp in seconds (10 digits)
const nowSeconds = Math.floor(Date.now() / 1000);
console.log(nowSeconds);
Convert Unix Seconds or Milliseconds to a Date Object
When an API returns Unix seconds (such as a Stripe webhook or JWT exp claim), multiply by 1000 inside the Date constructor. Never use Math.round() when computing current seconds because rounding up pushes the timestamp one second into the future.
const unixSeconds = 1764892800;
const date = new Date(unixSeconds * 1000);
// Output RFC 3339 / ISO 8601 UTC string
console.log(date.toISOString());
Format a Timestamp Into Any IANA Timezone
Never write manual offset math like + 5 * 3600 for user interfaces, because Daylight Saving Time will break your math twice a year. Use the native Intl.DateTimeFormat API with a valid IANA timezone name instead.
const date = new Date(1764892800 * 1000);
const formatter = new Intl.DateTimeFormat("en-US", {
timeZone: "America/New_York",
dateStyle: "medium",
timeStyle: "short"
});
console.log(formatter.format(date));
Common JavaScript Date Parsing Trap
Be careful when converting human date strings back into Unix timestamps. In JavaScript, new Date("2026-12-05") parses as midnight UTC, whereas new Date("2026-12-05T00:00:00") without a Z parses in the user's local browser timezone. Always include Z or an explicit offset when calling Date.parse().