The Problem with Dates
Is 06/07/2026 June 7th or July 6th? It depends on whether the author follows MM/DD/YYYY (US) or DD/MM/YYYY (most of the world). ISO 8601 eliminates all ambiguity by defining a single universal format.
The Format
Date only: 2026-06-13
Date + time: 2026-06-13T10:30:00
UTC time: 2026-06-13T10:30:00Z (Z = UTC)
With offset: 2026-06-13T10:30:00+05:30 (India Standard Time)
With milliseconds: 2026-06-13T10:30:00.000Z
Always Use UTC in APIs
Store and transmit timestamps in UTC (Z suffix or +00:00). Convert to local time only at the display layer. This prevents bugs where a date stored in one timezone is interpreted differently when read back in another.
// JavaScript
new Date().toISOString() // → "2026-06-13T10:30:00.000Z"
// Python
from datetime import datetime, timezone
datetime.now(timezone.utc).isoformat()
// PostgreSQL
SELECT NOW()::timestamptz; -- returns UTC timestamp
Sortable as a String
ISO 8601's year-first ordering means dates sort correctly as plain strings: "2026-06-13" > "2026-01-01" is true in lexicographic comparison. No date parsing required for ordering — a significant advantage in logs, filenames, and database text columns.
Durations
P1Y → 1 year
P3M → 3 months
PT2H30M → 2 hours, 30 minutes
P1DT12H → 1 day, 12 hours
Parsing in JavaScript
const d = new Date("2026-06-13T10:30:00.000Z");
d.toLocaleDateString("en-IN", { timeZone: "Asia/Kolkata" });
// → "13/6/2026" (displayed in user's local timezone)