A practical guide to the ISO 8601 date/time standard — formats, timezone notation, durations, and how to use it in your APIs.
Without a standard, dates are ambiguous: is 02/03/2025 February 3 or March 2?
ISO 8601 eliminates ambiguity with a globally unambiguous, sortable format.
Date: 2025-02-22
Time: 14:30:00
DateTime: 2025-02-22T14:30:00
With ms: 2025-02-22T14:30:00.123
UTC (Zulu): 2025-02-22T14:30:00Z
Offset +8: 2025-02-22T22:30:00+08:00
Offset -5: 2025-02-22T09:30:00-05:00
Always prefer Z (UTC) in APIs.
ISO 8601 durations follow the pattern P[n]Y[n]M[n]DT[n]H[n]M[n]S:
P1Y2M3DT4H5M6S -> 1 year, 2 months, 3 days, 4 hours, 5 minutes, 6 seconds
P30D -> 30 days
PT15M -> 15 minutes
| Wrong | Right | Reason |
|---|---|---|
2025/02/22 | 2025-02-22 | Slashes not ISO 8601 |
2025-2-5 | 2025-02-05 | Must zero-pad |
+0800 | +08:00 | Colon required |
ISO 8601 strings sort correctly as text, making them ideal for DB indexes and API responses.