Convert between ISO 8601 and Unix timestamps

How ISO 8601 to epoch conversion works, what it changes, where time zones, milliseconds and leap seconds cause errors, and when to keep a readable date.

ISO 8601 strings and Unix timestamps both identify a moment in time. One is meant for people and the other for machines. Converting between them is common in logs, APIs, spreadsheets and localization pipelines. Whether the conversion is safe depends on details the two formats handle differently: time zone offsets, precision and how the result will be read afterward. This review explains what the conversion changes, where meaning can be lost, and when to keep the readable form.

Is converting ISO 8601 to an epoch value suitable for your use?

For storage, computation and data exchange between systems, converting an ISO 8601 date-time to a Unix timestamp is usually suitable, with one condition: the source string must state its offset or the UTC designator "Z". A single integer is easy to compare, sort and subtract, and it removes ambiguity about how the date was written.

The main tradeoff is readability, along with the original offset. An epoch value records the instant but not the local time or time zone in which it was written. Converting back produces a correct instant, but usually expressed in UTC rather than the original local offset.

Keep the ISO 8601 form, or a locale-formatted date, in these cases:

  • People will read, review or edit the value directly.
  • The original local time or offset carries meaning, such as a scheduled event in a specific city.
  • The value is a calendar date with no time of day, such as a birthday or a due date. Converting it to an instant forces you to choose a time and a zone it never had.
  • The destination expects text dates, such as a document, a user interface label or a translation file.

What the conversion actually changes

This is a change of notation, not of presentation. Reverse, mirror and "font" tools only change how text looks, or reorder its characters. This conversion replaces the stored characters entirely: a structured date string becomes a decimal number, or the reverse. No styling, Unicode substitution or bidirectional display is involved. Both forms are plain ASCII digits and punctuation.

A Unix timestamp counts seconds elapsed since 1970-01-01T00:00:00Z, the Unix epoch. In standard POSIX time, every day has exactly 86,400 seconds and leap seconds are not counted. An ISO 8601 date-time writes the same instant as calendar fields: year, month, day, hour, minute, second, optional fractional seconds, and an optional offset from UTC.

The following values all describe the same instant:

Notation | Value | Note
ISO 8601, UTC | 2024-01-01T00:00:00Z | Z means zero offset
ISO 8601, with offset | 2024-01-01T02:00:00+02:00 | Same instant, local time two hours ahead of UTC
Unix time, seconds | 1704067200 | 19,723 days × 86,400 seconds
Unix time, milliseconds | 1704067200000 | Common in JavaScript and many APIs

Converting the second row to an epoch value and back typically produces the first row. The instant is preserved, but the +02:00 offset is not. If the offset matters, store it separately or keep the original string alongside the timestamp.

Where meaning can be lost or misread

  • Missing offset: an ISO 8601 date-time without "Z" or an offset is local time of an unstated zone. Converters fill the gap with an assumption, usually the machine's local zone or UTC, and different tools assume differently.
  • Date-only strings: in JavaScript, a date-only string such as 2024-01-01 is parsed as UTC. A date-time without an offset, such as 2024-01-01T00:00, is parsed as local time. The two can produce different epoch values on the same machine.
  • Seconds versus milliseconds: for present-day dates, a seconds value has 10 digits and a milliseconds value has 13. Reading one as the other shifts the date by decades or produces a far-future year.
  • Fractional seconds: an integer seconds timestamp drops anything below one second. Keep milliseconds, or a decimal value, if sub-second order matters.
  • Leap seconds: ISO 8601 can express a time such as 23:59:60, but POSIX Unix time has no distinct value for it. Converters handle this inconsistently.
  • Range limits: systems that store Unix time as a signed 32-bit integer cannot represent instants after 2038-01-19T03:14:07Z. Very old or far-future dates may also fall outside a given tool's supported range.

Reference conversions

The snippets below use widely documented standard functions. Each states its offset explicitly, so the result does not depend on the machine's time zone. Run them in your own environment rather than relying on the outputs shown here.

# GNU date (Linux)
date -u -d '2024-01-01T00:00:00Z' +%s
# 1704067200
date -u -d @1704067200 +%Y-%m-%dT%H:%M:%SZ
# 2024-01-01T00:00:00Z
# Python
from datetime import datetime, timezone
datetime.fromisoformat("2024-01-01T00:00:00+00:00").timestamp()
# 1704067200.0
datetime.fromtimestamp(1704067200, tz=timezone.utc).isoformat()
# '2024-01-01T00:00:00+00:00'
// JavaScript
Date.parse("2024-01-01T00:00:00Z") / 1000
// 1704067200
new Date(1704067200 * 1000).toISOString()
// "2024-01-01T00:00:00.000Z"

Two environment details are worth knowing. Python's fromisoformat accepts the trailing "Z" only from Python 3.11 onward. A Python datetime without time zone information is treated as local time when you call timestamp(). The BSD date command shipped with macOS uses different flags from GNU date, so the shell example does not run there unchanged.

Will the result stay readable and usable after copying or sharing?

Both formats are plain characters, so copying does not alter them in the way styled Unicode text can be altered. The risk comes from the destination reinterpreting the value. A spreadsheet or form may recognize an ISO string as a date and reformat it. It may also display a long integer in a shortened or scientific form. Neither behavior was tested for any named application here. If the destination is a spreadsheet, a CMS or a translation tool, paste a sample and confirm the stored value has not changed.

For readability, the two forms differ sharply. An ISO 8601 string can be read and checked by a person. When all values use the same format and the same offset, it also sorts correctly as text. An epoch value tells a reader nothing without conversion, and a screen reader will typically announce it as a long number. No assistive technology was tested for this review. As a general principle, a raw timestamp is not an accessible way to communicate a date.

For US audiences, ISO 8601 is not the everyday display convention. Many readers expect month-first dates and 12-hour clock times. A practical localization pattern is to keep ISO 8601 or epoch values for storage and exchange, then format them for each locale only at display time. In web pages, the HTML time element supports this split. Its datetime attribute holds a machine-readable value in an ISO 8601-based format, while its visible text can follow local conventions. That attribute does not accept a bare Unix timestamp.

Provide a plain-text, human-readable equivalent whenever people will see the value. This applies to emails, reports, support tickets, exported files meant for review, and content that will be translated or read aloud.

Evidence gaps

No specific online converter or library version was evaluated for this review. No measurements, test results or privacy assessments are reported. The behaviors described come from the documented definitions of Unix time and ISO 8601 and from standard language functions. If you use a web-based converter, check its documentation for how it treats missing offsets, milliseconds and the data you paste. Its appearance alone does not show how it handles your input.