Unix timestamps: seconds, milliseconds and time zones
Check the API unit before converting. Ten-digit seconds and thirteen-digit milliseconds are common today, but digit count is only a heuristic. Choose an explicit unit for historical or far-future dates.
Converting seconds and milliseconds
Unix time starts at 1970-01-01 00:00:00 UTC. JavaScript Date uses milliseconds.
// 2024-01-01 00:00:00 UTC
const seconds = 1704067200;
const milliseconds = seconds * 1000;
new Date(milliseconds).toISOString();
// "2024-01-01T00:00:00.000Z"
Math.floor(Date.now() / 1000); // Unix secondsPassing seconds directly to new Date() often produces a date near 1970. The example button fills a real input; the pale “e.g.” text is a placeholder.
One instant, different time zones
1704067200 seconds displays as 2024-01-01 00:00:00 in UTC and 2024-01-01 08:00:00 in Asia/Shanghai. Changing the display zone does not change the timestamp.
Dates without an offset need a selected time zone. 2024-01-01T00:00:00Z explicitly means UTC; +08:00 explicitly supplies an offset. Use an offset to disambiguate repeated daylight-saving times.