Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

How Do You Turn a Unix Timestamp Into a JavaScript Date?

Convert Unix seconds to a JavaScript Date by multiplying by 1,000. Learn how to distinguish seconds from milliseconds, format UTC or local output, and validate the result.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a Unix timestamp in seconds, multiply by 1,000 before passing it to JavaScript’s Date constructor: new Date(unixSeconds * 1000). JavaScript date values use milliseconds, so passing seconds directly usually produces a date near the start of 1970.

Convert Unix seconds to a JavaScript Date

A common Unix timestamp counts seconds since 1970-01-01 00:00:00 UTC. JavaScript’s numeric Date time value counts milliseconds from that epoch. Multiply seconds by 1,000 to convert the unit:

As an Amazon Associate I earn from qualifying purchases.

const unixSeconds = 1_700_000_000;
const date = new Date(unixSeconds * 1000);

console.log(date.toISOString());
// 2023-11-14T22:13:20.000Z

The multiplication changes seconds into milliseconds; it does not convert the instant to another time zone. A JavaScript Date represents an instant. The method used to display it determines the time-zone presentation. MDN explains the millisecond representation in its guide to representing dates and times.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check whether the input is seconds or milliseconds

Do not multiply a timestamp that is already in milliseconds. Apply the conversion at the point the value enters your application, based on the source’s contract rather than an unexplained guess about its size.

  • Seconds: new Date(timestamp * 1000)
  • Milliseconds: new Date(timestamp)
const seconds = 1_700_000_000;
const milliseconds = 1_700_000_000_000;

const fromSeconds = new Date(seconds * 1000);
const fromMilliseconds = new Date(milliseconds);

The constructor matters: use new Date(value) to create a date from a numeric timestamp. Calling Date(value) without new returns the current date-time as a string and ignores the supplied argument. See MDN’s Date() constructor reference.

Choose the right output and time zone

Use the output method that matches the consumer. For stable, machine-readable UTC text, call toISOString(); its result ends in Z. For people, use toLocaleString(). If the display must follow a particular region’s time-zone rules, pass an explicit IANA time-zone identifier rather than relying on the computer’s configured zone.

Need Use Time-zone behavior
Standard UTC string for data exchange date.toISOString() UTC; ends in Z
Display in the runtime’s local zone date.toString() Uses the host’s local time zone
Localized display in a chosen region date.toLocaleString("en-US", { timeZone: "America/Los_Angeles" }) Uses the specified zone’s rules
const date = new Date(unixSeconds * 1000);

const utcText = date.toISOString();
const localText = date.toLocaleString("en-US", {
  timeZone: "America/Los_Angeles",
});

Local display can show a different clock time or calendar date from UTC, depending on the zone. For details, see MDN’s references for toISOString() and toString().

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Validate the timestamp and handle edge cases

A numeric value outside JavaScript’s supported Date range, or a value that cannot produce a valid date, results in an invalid Date. The supported range is ±8,640,000,000,000,000 milliseconds from the epoch. Check the resulting time value with Number.isNaN(date.getTime()) before using it:

function dateFromUnixSeconds(unixSeconds) {
  const date = new Date(unixSeconds * 1000);

  if (Number.isNaN(date.getTime())) {
    throw new RangeError("Timestamp is outside the supported Date range");
  }

  return date;
}

Negative timestamps are valid when they fall within the supported range; they represent instants before 1970-01-01 UTC. Fractional seconds may also be supplied. If a source system specifies how fractional values must be rounded or truncated, follow that contract; do not silently impose a rounding rule of your own. MDN documents the constructor’s supported range and invalid-date behavior.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why does my JavaScript date show 1970?

The usual cause is passing a seconds-based Unix timestamp directly to new Date(). The constructor interprets a number as milliseconds, so a seconds value is treated as a much smaller interval after the epoch. If the input is in seconds, use new Date(timestamp * 1000); if it is already in milliseconds, pass it directly. Numeric timestamps can be converted without Date.parse() or an intermediate date string.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.