ISO 8601 format with examples is the international standard for representing dates, times, durations, and intervals in a clear, unambiguous, and machine-readable way. Widely adopted in computing, APIs, databases, JSON, XML, and data interchange, ISO 8601 eliminates confusion from regional formats (MM/DD/YYYY vs DD/MM/YYYY) and ensures consistent sorting, parsing, and comparison. In 2026, ISO 8601 remains the gold standard — used everywhere from timestamps in logs and databases to calendar APIs, financial transactions, scientific data, and modern web services. Mastering it is essential for reliable, interoperable code.
Here’s a complete, practical guide to ISO 8601: core formats for dates, times, datetimes, time zones, durations, periods, week dates, real-world patterns, and best practices for parsing, formatting, and using ISO 8601 in Python and pandas/Polars.
The basic date format is YYYY-MM-DD — four-digit year, two-digit month, two-digit day, zero-padded, hyphen-separated — always unambiguous and sortable.
from datetime import date
d = date(2026, 2, 10)
print(d.isoformat()) # '2026-02-10' (standard date only)
Time format is HH:MM:SS (24-hour, zero-padded) — often combined with date using T separator for full datetime: YYYY-MM-DDTHH:MM:SS.
from datetime import datetime
dt = datetime(2026, 2, 10, 14, 30, 45)
print(dt.isoformat()) # '2026-02-10T14:30:45' (basic datetime)
# With microseconds
dt_micro = datetime(2026, 2, 10, 14, 30, 45, 123456)
print(dt_micro.isoformat()) # '2026-02-10T14:30:45.123456'
Time zones are appended as offset from UTC — +HH:MM or -HH:MM; Z for UTC (zero offset).
from zoneinfo import ZoneInfo
ny_dt = datetime(2026, 2, 10, 14, 30, tzinfo=ZoneInfo("America/New_York"))
print(ny_dt.isoformat()) # '2026-02-10T14:30:00-05:00'
utc_dt = datetime(2026, 2, 10, 19, 30, tzinfo=ZoneInfo("UTC"))
print(utc_dt.isoformat()) # '2026-02-10T19:30:00+00:00' or '2026-02-10T19:30:00Z'
Week dates use YYYY-Www (week number 01–53) or YYYY-Www-D (weekday 1–7, Monday=1).
# ISO week date (2026-W06-2 = Tuesday of week 6, 2026)
week_date = date.fromisocalendar(2026, 6, 2)
print(week_date.isoformat()) # '2026-02-10'
Durations and periods start with P — PT1H30M (1 hour 30 minutes), P1Y2M3D (1 year 2 months 3 days), P2026-02-10T14:30:00/2026-03-10 (period from start to end).
delta = timedelta(days=45, hours=3)
print(delta) # 45 days, 3:00:00
# No direct ISO duration in stdlib — use libraries like isodate or pendulum
Real-world pattern: API payloads, database timestamps, logging, and data interchange — ISO 8601 ensures consistency across systems and time zones.
# pandas: convert column to ISO strings
df = pd.DataFrame({'event': [datetime(2026, 1, 15, 9, 0), datetime(2026, 2, 10, 14, 30)]})
df['iso_timestamp'] = df['event'].dt.strftime('%Y-%m-%dT%H:%M:%S')
print(df)
Best practices make ISO 8601 usage reliable and interoperable. Always use .isoformat() for machine-readable output — YYYY-MM-DDTHH:MM:SS or with offset. Prefer UTC (Z or +00:00) for storage and interchange — convert local times only for display. Modern tip: use Polars for large timestamp columns — pl.col("ts").dt.strftime("%Y-%m-%dT%H:%M:%S") is 10–100× faster than pandas. Add type hints — datetime.datetime or datetime.date — improves readability and mypy checks. Parse ISO strings with fromisoformat() (Python 3.7+) — faster and safer than strptime(). Handle time zones with zoneinfo — avoid pytz in new code. For durations/periods, use pendulum or isodate — stdlib lacks full ISO duration support. Validate inputs — wrap parsing in try/except ValueError. Use ISO week dates for week-based reporting — date.isocalendar() gives year, week, weekday.
ISO 8601 format with examples is the universal language of dates and times — unambiguous, sortable, and interoperable. In 2026, use .isoformat() for output, fromisoformat() for input, UTC everywhere, type hints for safety, and Polars for scale. Master ISO 8601, and you’ll handle timestamps, intervals, and time zones correctly across systems and applications.
Next time you need to represent or exchange a date/time — reach for ISO 8601. It’s Python’s cleanest way to say: “This moment, in a format everyone understands.”