Engineer IDEA

dt

ISO Date and Time Formats

Key Elements of ISO Date and Time Formats

1. Date

The ISO format for dates is YYYY-MM-DD:

  • YYYY: Four-digit year (e.g., 2024)
  • MM: Two-digit month (01 through 12)
  • DD: Two-digit day (01 through 31)

Example: 2024-12-09 (December 9, 2024)

2. Time

The ISO format for time is hh:mm:ss:

  • hh: Two-digit hour (00 through 23, 24-hour clock)
  • mm: Two-digit minute (00 through 59)
  • ss: Two-digit second (00 through 59)

Example: 15:30:00 (3:30 PM)

3. Combined Date and Time

When date and time are combined, the format is: YYYY-MM-DDTHH:mm:ss (The letter “T” separates the date and time components).

Example: 2024-12-09T15:30:00

4. Time Zone

To specify time zones, ISO 8601 uses UTC offsets. The time can include an offset from UTC (Coordinated Universal Time) with the format ±hh:mm:

  • The + or - indicates the offset from UTC.
  • hh is the number of hours offset.
  • mm is the number of minutes offset.

Example: 2024-12-09T15:30:00+02:00 (2-hour ahead of UTC)

Alternatively, Z is used to indicate UTC time (zero offset). Example: 2024-12-09T15:30:00Z (UTC time)

5. Week Date

ISO 8601 also defines week-based dates, which can be represented as YYYY-Www-D:

  • YYYY: Four-digit year
  • Www: Week number (01 through 53)
  • D: Day of the week (1 through 7)

Example: 2024-W49-7 (Sunday of the 49th week of 2024)

6. Ordinal Date

This format expresses the day of the year, starting from 001 to 365 (or 366 for leap years). The format is YYYY-DDD:

  • YYYY: Four-digit year
  • DDD: Day of the year (001 to 366)

Example: 2024-344 (the 344th day of 2024, which is December 9)

Examples of Full Date and Time Formats:

  • Complete date and time with time zone: 2024-12-09T15:30:00+02:00
  • Date with week number: 2024-W49-7
  • Date with ordinal: 2024-344

Precision and Extended Formats

ISO 8601 allows for precision down to fractions of a second:

  • For instance, hh:mm:ss.sss can represent milliseconds.
  • Example: 2024-12-09T15:30:00.123+02:00 (with milliseconds and offset).

These formats are widely used in computing, APIs, databases, and international communication due to their unambiguous nature and global standardization.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top