Developer Tools

ISO 8601 Date Format: The International Standard Explained

ISO 8601 is the international standard for representing dates and times. Learn the format, why it matters for software, and how to use it correctly.

VR
Vikram Rao

Senior Software Engineer

2026年3月10日·6 分で読める

What Is ISO 8601?

ISO 8601 is the international standard for representing dates and times, published by the International Organization for Standardization (ISO). First published in 1988 and most recently updated in 2019 (ISO 8601-1:2019 and ISO 8601-2:2019), it defines a globally unambiguous way to write dates, times, durations, and intervals using a consistent format based on the Gregorian calendar.

The core problem ISO 8601 solves is a simple one: the date "03/04/05" is deeply ambiguous. Is it March 4, 2005? April 3, 2005? April 5, 2003? May 4, 2003? Depending on whether you follow the US (MM/DD/YY), European (DD/MM/YY), or other conventions, the answer differs. In software, APIs, databases, and international communications, this ambiguity is unacceptable.

ISO 8601 eliminates this ambiguity by mandating a single, specific ordering: from the largest unit to the smallest — year, then month, then day, then hour, then minute, then second. This is not just a style choice; it is a functional design that makes dates both human-readable and machine-sortable.

The Basic Date Format: YYYY-MM-DD

The most commonly used ISO 8601 format is the calendar date:

2026-03-13  (March 13, 2026)

The format components are:

  • YYYY — Four-digit year. Using four digits avoids the Y2K-style ambiguity of two-digit years.
  • MM — Two-digit month (01–12). Zero-padded, so January is "01" not "1".
  • DD — Two-digit day (01–31). Zero-padded.
  • Hyphens — The separators (-) are part of the "extended format". The "basic format" omits separators: 20260313. Extended format is strongly preferred for human readability.

The critical insight is that YYYY-MM-DD dates sort correctly as plain strings. Sort a list of ISO 8601 dates alphabetically and you get them in chronological order. This is not true of any other common date format (MM/DD/YYYY sorts by month, DD/MM/YYYY sorts by day). This property makes ISO 8601 dates ideal for filenames, database keys, and any context where lexicographic and chronological ordering should align.

Combined Date and Time: The Datetime Format

ISO 8601 combines date and time using the letter "T" as a separator:

2026-03-13T15:30:00        (March 13, 2026 at 3:30 PM, no timezone specified)
2026-03-13T15:30:00Z       (same, in UTC — the Z means "Zulu time" = UTC)
2026-03-13T15:30:00+05:30  (same, in India Standard Time, UTC+5:30)
2026-03-13T15:30:00-05:00  (same, in US Eastern Standard Time, UTC-5)

The time components are:

  • T — Separator between date and time portions.
  • HH — Two-digit hour in 24-hour format (00–23).
  • MM — Two-digit minutes (00–59).
  • SS — Two-digit seconds (00–59, or 00–60 to accommodate leap seconds).
  • .sss — Optional decimal fraction of seconds. 2026-03-13T15:30:00.123Z includes milliseconds.

The UTC Indicator (Z) and Timezone Offsets

The timezone designator is one of the most important parts of an ISO 8601 datetime for software purposes:

  • Z (Zulu) — Indicates UTC. 2026-03-13T00:00:00Z is unambiguously midnight UTC on March 13, 2026. "Zulu" comes from the NATO phonetic alphabet's name for the letter Z, which the US military uses to denote UTC.
  • +HH:MM or -HH:MM — A numeric offset from UTC. +05:30 means UTC plus 5 hours and 30 minutes (India). -08:00 means UTC minus 8 hours (US Pacific Standard Time).
  • No designator — If there is no timezone designator, the datetime is "local time" with no timezone information. This is valid ISO 8601 but should be avoided in APIs and databases, as it creates ambiguity.

Best practice in software: always include the timezone designator, and prefer Z (UTC) for stored timestamps. Apply local timezone offsets only at display time.

Duration Format: P1Y2M3DT4H5M6S

ISO 8601 also defines a format for durations — spans of time rather than specific moments. The format starts with "P" (for "period") and uses letter designators for each component:

P1Y        — 1 year
P6M        — 6 months
P3W        — 3 weeks
P10D       — 10 days
PT4H       — 4 hours (the T separates date components from time components)
PT30M      — 30 minutes
PT45S      — 45 seconds
P1Y2M3DT4H5M6S  — 1 year, 2 months, 3 days, 4 hours, 5 minutes, 6 seconds

Duration format is used in APIs (the ISO 8601 duration is the format used by AWS for Lambda timeout settings, for example), in XML schemas, and in HTML's <time> element's datetime attribute.

Week Format: YYYY-Www-D

ISO 8601 defines a week-numbering system where the first week of a year is the week containing the year's first Thursday. Weeks always start on Monday. The format is:

2026-W11      — Week 11 of 2026
2026-W11-5    — Friday (day 5) of week 11 of 2026

ISO week numbers are widely used in European business contexts. Note that ISO week numbering can cause a date like December 31 to be in week 1 of the following year, or January 1 to be in week 52 or 53 of the previous year — a common source of bugs in software that mixes week numbers with calendar years.

Ordinal Dates: YYYY-DDD

ISO 8601 also supports ordinal dates, which represent a date as a year and a day-of-year number (1–365, or 1–366 in leap years):

2026-072    — The 72nd day of 2026 (March 13, 2026)

Ordinal dates are used in some scientific and industrial applications where sequential day counting is more useful than calendar month/day notation.

Why ISO 8601 Matters for APIs and Databases

ISO 8601 is the date format of the modern Internet. RFC 3339 (the timestamp format used in HTTP headers, JSON APIs, and most web protocols) is a profile of ISO 8601. The Temporal API (the modern JavaScript date/time proposal) uses ISO 8601 strings throughout. JSON Web Tokens use ISO 8601 for their iat and exp fields when expressed as strings.

Key reasons to use ISO 8601 in your APIs and databases:

  • Unambiguous: No locale-specific interpretation of month/day order.
  • Sortable: String comparison yields chronological order.
  • Interoperable: Understood natively by JavaScript, Python, Java, PostgreSQL, MySQL, SQLite, and virtually every modern programming environment.
  • Self-documenting: A human reading 2026-03-13T15:30:00Z immediately understands it without needing to know the locale or conventions of the system that produced it.

ISO 8601 in Common Programming Languages

JavaScript / TypeScript

// ISO 8601 string from Date object
new Date().toISOString(); // "2026-03-13T15:30:00.000Z"

// Parse ISO 8601 string
new Date("2026-03-13T15:30:00Z"); // Date object

// Date portion only
new Date().toISOString().slice(0, 10); // "2026-03-13"

Python

from datetime import datetime, timezone, date

# Current UTC datetime as ISO 8601
datetime.now(timezone.utc).isoformat()  # "2026-03-13T15:30:00+00:00"

# Date only
date.today().isoformat()  # "2026-03-13"

# Parse ISO 8601 string (Python 3.7+)
dt = datetime.fromisoformat("2026-03-13T15:30:00+00:00")

Java (java.time — Java 8+)

import java.time.*;

// Current UTC instant as ISO 8601
Instant.now().toString(); // "2026-03-13T15:30:00Z"

// LocalDate as ISO 8601
LocalDate.now().toString(); // "2026-03-13"

// Parse ISO 8601 datetime
ZonedDateTime zdt = ZonedDateTime.parse("2026-03-13T15:30:00+05:30");

PostgreSQL

-- Store as TIMESTAMPTZ (ISO 8601 compatible)
CREATE TABLE events (
  id SERIAL PRIMARY KEY,
  created_at TIMESTAMPTZ DEFAULT NOW()
);

-- ISO 8601 input is accepted natively
INSERT INTO events (created_at) VALUES ('2026-03-13T15:30:00Z');

-- ISO 8601 output
SELECT TO_CHAR(created_at, 'YYYY-MM-DD"T"HH24:MI:SS"Z"') FROM events;

Common Mistakes to Avoid

  • Omitting the timezone: 2026-03-13T15:30:00 without a timezone designator is ambiguous. Always add Z for UTC or an explicit offset.
  • Confusing ISO week years: The ISO week year can differ from the calendar year in late December and early January. Never use YYYY (calendar year) with WW (ISO week number) — use the correct week-year designator (GGGG in most date formatting libraries).
  • Two-digit years: ISO 8601 requires four-digit years. Never use two-digit year representations in APIs or databases.
  • Locale-specific formats: "13/03/2026" and "03/13/2026" are not ISO 8601. Always use YYYY-MM-DD.

Frequently Asked Questions

What is the ISO 8601 date format?

The ISO 8601 date format is YYYY-MM-DD (year-month-day), such as 2026-03-13 for March 13, 2026. This international standard orders date components from largest to smallest, eliminating the ambiguity caused by regional formats like MM/DD/YYYY (US) or DD/MM/YYYY (Europe).

What does the T mean in ISO 8601?

The letter "T" in an ISO 8601 datetime string (e.g., 2026-03-13T15:30:00Z) is a separator between the date and time portions. It is required by the standard to distinguish where the date ends and the time begins, and it has no other meaning.

What does the Z mean in a timestamp?

The "Z" at the end of an ISO 8601 timestamp indicates UTC (Coordinated Universal Time). It stands for "Zulu time," the NATO phonetic alphabet designation for the letter Z. A timestamp ending in Z, such as 2026-03-13T15:30:00Z, means the time is expressed in UTC with zero offset.

Why is ISO 8601 better than other date formats?

ISO 8601 is unambiguous (no confusion between month/day order), string-sortable (alphabetical sort equals chronological sort), internationally recognized, and supported natively by virtually every programming language and database. It eliminates the locale-dependent interpretation problems that plague formats like MM/DD/YYYY.

What is an ISO 8601 duration?

An ISO 8601 duration uses the format P[n]Y[n]M[n]DT[n]H[n]M[n]S, where P means "period" and T separates date from time components. For example, P1Y2M3DT4H5M6S represents 1 year, 2 months, 3 days, 4 hours, 5 minutes, and 6 seconds. PT30M means 30 minutes.

What is an ISO week number?

ISO 8601 defines week numbers where Week 1 is the week containing the first Thursday of the year, and weeks always start on Monday. The format is YYYY-Www (e.g., 2026-W11). ISO week numbering is widely used in European business, logistics, and project planning contexts.

Is RFC 3339 the same as ISO 8601?

RFC 3339 is a profile (subset) of ISO 8601 designed specifically for Internet timestamps. It restricts ISO 8601 to a single unambiguous format suitable for HTTP headers, JSON APIs, and web protocols. All RFC 3339 timestamps are valid ISO 8601, but not all ISO 8601 formats are valid RFC 3339.

Sources

  • ISO 8601-1:2019 — Date and time — Representations for information interchange
  • RFC 3339: Date and Time on the Internet: Timestamps (IETF)
  • TC39 Temporal Proposal — ECMAScript temporal API documentation
  • PostgreSQL Documentation: Date/Time Types

VR

著者について

Vikram Rao

Senior Software Engineer

Vikram Rao has been writing timezone-resilient software for fourteen years, building scheduling infrastructure for distributed teams. He has spoken at multiple developer conferences on the surprisingly difficult topic of handling dates and

全プロフィールを読む →
ブログに戻る

関連記事