← All posts

Convert Unix Timestamps to Readable Dates: Seconds, Milliseconds and UTC

Convert epoch values in both directions with worked UTC examples, JavaScript Date code, and checks for time-zone and unit mistakes.

Convert Unix Timestamps to Readable Dates: Seconds, Milliseconds and UTC

When an API date looks decades away from the expected result, first check its unit. A Unix timestamp is commonly expressed in seconds, while JavaScript's Date constructor accepts a numeric value in milliseconds. The timestamp converter displays readable dates so you can compare the same instant in UTC, local time and ISO notation.

Start with a known value

Use this reference when checking your workflow:

Representation Value
Epoch seconds 1704067200
Epoch milliseconds 1704067200000
ISO UTC 2024-01-01T00:00:00.000Z

Enter the value in the converter, confirm the unit and inspect the UTC result. Your local display can show a different calendar date or clock time because it uses the browser's time zone. That does not mean the instant changed.

Convert seconds with JavaScript

const epochSeconds = 1704067200;
const instant = new Date(epochSeconds * 1000);
console.log(instant.toISOString());
// 2024-01-01T00:00:00.000Z

For a millisecond value, omit the multiplication:

const epochMilliseconds = 1704067200000;
console.log(new Date(epochMilliseconds).toISOString());

Confirm the unit in the source API documentation. Digit count is a convenient hint for modern dates, not a complete rule: old timestamps, negative values and far-future dates need explicit handling.

Convert a date back to epoch time

Use an explicit offset for a reproducible result:

const date = new Date('2024-01-01T00:00:00Z');
const milliseconds = date.getTime();
if (!Number.isFinite(milliseconds)) throw new Error('Invalid date');
const seconds = Math.floor(milliseconds / 1000);
console.log({ seconds, milliseconds });

For modern dates, flooring removes fractional seconds. If your system handles dates before 1970, confirm its rounding policy: flooring a negative fractional value differs from truncating it toward zero.

A timestamp does not contain the user's time-zone preference. Store the instant separately from any region needed for future local scheduling. Daylight-saving changes can make a local clock reading ambiguous or nonexistent; an explicit UTC offset resolves the instant for a particular occurrence.

Check an apparently incorrect result

  1. Confirm whether the source is seconds, milliseconds or a different unit.
  2. Check that the number was copied completely without separators or rounding.
  3. Compare the UTC output before interpreting the local display.
  4. Use ISO input with Z or an explicit offset instead of a locale-specific date string.
  5. Reject invalid dates before calling methods such as toISOString().

The MDN Date reference documents the numeric representation and date-parsing behavior. For JWT claims, use seconds as described in the JWT guide.

Verify your actual application

A converter is a debugging aid. It cannot know an API's unit, retention policy or scheduling rules. Add a known instant to your application's tests and compare both directions. Inspect the serialized value with the JSON formatter, especially when a timestamp arrives as a string instead of a number.

Try this workflow

Use Timestamp Converter and inspect the result using the checks in this guide.

Open Timestamp Converter