ISO 8601 Date Format
Master the ISO 8601 date and time format used in APIs and databases. Learn the syntax, timezone handling, and parsing in multiple languages.
Format
2024-01-15T09:30:00Z
Detailed Explanation
ISO 8601 is the international standard for representing dates and times as strings. Its format is unambiguous, sortable, and universally understood by parsers. The most common form is YYYY-MM-DDTHH:mm:ssZ, where the T separates date from time and Z indicates UTC.
Format variations:
Date only: 2024-01-15
Date and time: 2024-01-15T09:30:00
With UTC: 2024-01-15T09:30:00Z
With offset: 2024-01-15T09:30:00+05:30
With milliseconds: 2024-01-15T09:30:00.123Z
Week date: 2024-W03-1 (Week 3, Monday)
Ordinal date: 2024-015 (15th day of 2024)
Why it matters for developers:
ISO 8601 strings sort lexicographically in the same order as chronologically, making them ideal for filenames, log entries, and database indexes. The format is the default output for JavaScript's Date.toISOString(), JSON serialization in most frameworks, and the timestamptz display in PostgreSQL.
Parsing in different languages:
// JavaScript
new Date("2024-01-15T09:30:00Z")
# Python 3.7+
from datetime import datetime
datetime.fromisoformat("2024-01-15T09:30:00+00:00")
Common pitfalls:
The trailing Z is not optional in many parsers, and it specifically means UTC (it stands for "Zulu time" in military time zones). Omitting the timezone entirely can cause parsers to assume local time, leading to inconsistencies across servers. Also, be aware that JavaScript's Date constructor parses date-only strings like 2024-01-15 as UTC, but date-time strings without a timezone as local time — an inconsistency that has caused countless bugs.
Best practice: Always store and transmit dates in ISO 8601 with an explicit timezone designator. Convert to local time only at the presentation layer in your frontend.
Use Case
ISO 8601 is the standard format for REST API request and response bodies, ensuring that clients and servers across different timezones interpret dates identically.