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

Understand seconds, milliseconds and UTC with timestamp examples, JavaScript code and common date conversion fixes.

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

If an API date suddenly lands in 1970, check the units first. Unix timestamps often use seconds, while JavaScript's numeric Date constructor expects milliseconds. Mixing them up is easy.

The timestamp converter helps you compare a value in UTC, local time and ISO format.

Start with a value you know

These values all refer to the same instant:

Format Value
Seconds 1704067200
Milliseconds 1704067200000
UTC date 2024-01-01T00:00:00.000Z

Enter one and check the UTC result. Your local time may show a different hour or even a different calendar day. That's expected when the browser uses another time zone.

Convert seconds in JavaScript

Multiply seconds by 1,000:

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

For milliseconds, pass the number directly:

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

Check the source API's documentation for the unit. Counting digits can give you a clue for recent dates, but it isn't a reliable rule for every date.

Convert a date back to a timestamp

Include Z for UTC or an explicit offset:

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 });

Math.floor removes the fractional seconds here. For dates before 1970, check the rounding your system expects: flooring a negative fraction gives a different result from truncating it.

When the answer still looks wrong

Check whether the value was copied completely, whether it arrived as a number or string, and whether the source uses another unit. Compare UTC before looking at the local display.

Avoid ambiguous date strings such as 01/02/2024. Use ISO input with an offset and reject invalid dates before calling toISOString().

A timestamp represents an instant; it doesn't store someone's preferred time zone. For recurring local appointments, keep the relevant region as well. Daylight-saving changes can make a local clock time repeat or disappear.

The JavaScript Date reference covers parsing and numeric values. Add a known date to your application's tests so a unit mistake doesn't return unnoticed.

Try this workflow

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

Open Timestamp Converter