Unix Timestamp to ISO 8601

One number in, one machine-readable string out: YYYY-MM-DDTHH:MM:SS.mmmZ. The converter below prints the ISO row for any epoch value in s/ms/µs/ns — and the notes explain the two conventions everyone trips on.

[MOD.CONV // INSTRUMENT]

Unix timestamp → ISO 8601

Auto-detects seconds, ms, µs, ns

Date output is floored to milliseconds. Choose a unit explicitly for older dates or values outside auto-detection.

Typical today: 10 (s), 13 (ms), 16 (µs), 19 (ns) digits. A unit heuristic, not a definition.

01 Local time —
02 UTC standard —
03 ISO 8601 —
04 Relative —
[SUB.REVERSE]
SECONDS (S) —
MILLISECONDS (MS) —

Local means your device timezone. During a repeated daylight-saving hour, the earlier occurrence is used; use UTC to choose an unambiguous instant.

[SEC.02 // ALWAYS UTC]

toISOString() is always UTC — by design

THE Z RULE

JavaScript's new Date(1712345678901).toISOString() returns 2024-04-05T19:34:38.901Z regardless of the machine's timezone. That is not a limitation — the ISO-8601 format can carry offsets (19:34:38.901+08:00), but the JSON and API conventions standardized on the UTC form so that serialized timestamps compare equal across the world. The trailing Z is not a punctuation mark: it is the zone designator for UTC (from the NATO phonetic alphabet for "Zulu" time), and Z is exactly equivalent to an offset of +00:00.

  • A string without Z or an offset (2024-04-05T19:34:38) has no timezone — how it is parsed is implementation-behaviour territory; add the designator.
  • To convert offset-bearing local time to UTC, use UTC = local time − offset. For example, 2024-04-06T03:34:38+08:00 equals 2024-04-05T19:34:38Z; do not just strip the offset.
  • RFC 3339, the profile actually used by JSON APIs, allows lowercase z and t but most producers emit uppercase.
[SEC.03 // PRECISION]

Second, millisecond and microsecond precision

WHERE DIGITS DIE

toISOString() always prints exactly three fractional digits (milliseconds), zero-padded: ...38.901Z. That has two consequences:

  • Whole-second values still show .000 — it is padding, not unknown precision.
  • Micro- and nanosecond timestamps lose digits in a JS Date: it stores only milliseconds. Both six-digit (...38.901234Z) and nine-digit fractions are allowed by RFC 3339, but consumer precision and parser support vary. Preserve the original integer or a sufficiently precise string when sub-ms data matters.

Round-trip test worth running on any tool: convert the ISO string back. If the integer changes, precision died somewhere in the middle row.

[DOC.FAQ // INDEX]

ANSWERS

05 ITEMS
01 What does the Z mean at the end of an ISO 8601 timestamp?

UTC. Z is the zone designator for zero offset ("Zulu time"), identical to +00:00. 2024-04-05T19:34:38Z and 2024-04-05T20:34:38+01:00 name the same instant; strip either suffix and you no longer know which.

02 Is ISO 8601 the same as RFC 3339?

RFC 3339 is a strict subset of ISO 8601 for internet use. All RFC 3339 timestamps are ISO 8601; not the reverse (ISO allows week dates like 2024-W14 and more relaxed forms). For APIs, produce RFC 3339-compatible strings — YYYY-MM-DDTHH:MM:SS±HH:MM or the Z form — and you satisfy both.

03 Why is my converted ISO time 8 hours off from the local time?

Because one rendering is UTC and the other is your local wall clock, and your zone is UTC+8. Both describe the same instant. ISO strings serialized with toISOString() are always UTC; use toLocaleString() or an Intl.DateTimeFormat with a timeZone option for local renderings.

04 Can ISO 8601 represent microseconds or nanoseconds?

Yes. Six-digit microsecond and nine-digit nanosecond fractions are permitted by both ISO 8601 and RFC 3339. Actual support depends on the consumer: JavaScript Date stores milliseconds, while other libraries can retain more. Test the receiving parser and storage precision instead of assuming either length is universally safe.

05 How do I convert ISO 8601 back to a Unix timestamp?

Parse, then ask for milliseconds: Date.parse("2024-04-05T19:34:38Z") / 1000 gives 1712345678. Always include the designator when you parse — a bare local-looking string is exactly the ambiguity the timezone-trap section describes.

[SEC.MATRIX // RELATED]

Related tools

3 PAGES

Sources and specifications