YAML by Example: Date & Timestamp Values
1.2
Working with dates and times. ISO 8601 format support.
Code
# Date only (ISO 8601)
birth_date: 2000-01-15
release_date: 1995-12-31
# Full timestamp with time
created_at: 2024-03-15T14:30:00Z
updated_at: 2024-03-15T14:30:00.123Z
# Timestamp with timezone offset
event_time: 2024-03-15T14:30:00+05:30
meeting: 2024-03-15T09:00:00-08:00
# Canonical format (space separator)
canonical: 2024-03-15 14:30:00
# Without timezone (assumes UTC)
scheduled: 2024-03-15T14:30:00Explanation
YAML supports ISO 8601 date and timestamp formats. Date-only format is YYYY-MM-DD, and times are specified as HH:MM:SS with optional milliseconds. The T separator divides date and time, though a space also works.
Timezone is indicated by Z for UTC or an offset like +05:30 or -08:00. If you omit the timezone, UTC is assumed. Most YAML parsers convert these into proper date/datetime objects in your programming language.
Code Breakdown
2-3
Date-only format without time portion.
6
Z indicates UTC timezone (zero offset).
