Lesson 31 +10 XP

Date and Time Formats

Date and Time Formats

Some HTML attributes (like datetime on <time>, or date inputs) need dates and times written in a special computer-friendly way.

The golden rule

Write dates from biggest to smallest: Year-Month-Day.

This is the international standard (ISO 8601):

<time datetime="2026-08-08">August 8, 2026</time>

Date only

YYYY-MM-DD

<time datetime="2026-08-08">My birthday</time>

Adding a time

YYYY-MM-DDTHH:MM

The T is just a separator between date and time.

<time datetime="2026-08-08T15:30">Party at 3:30pm</time>

Time with seconds

HH:MM:SS

<time datetime="15:30:15">3:30pm and 15 seconds</time>

Time zones

Add a Z for UTC (the world's clock):

<time datetime="2026-08-08T15:30Z">3:30pm UTC</time>

Or a timezone offset like -05:00:

<time datetime="2026-08-08T15:30-05:00">Eastern time</time>

Months and weeks

  • Month: YYYY-MM
  • Week: YYYY-W##
<time datetime="2026-08">August 2026</time>

For date/time inputs

<input type="date"> uses YYYY-MM-DD, <input type="time"> uses HH:MM, and datetime-local uses YYYY-MM-DDTHH:MM.

The value and the display

Remember: the datetime value is for computers. What's inside the <time> tags is for humans!

TL;DR

  • Date format: YYYY-MM-DD.
  • Date + time: YYYY-MM-DDTHH:MM.
  • Timezone: add Z (UTC) or an offset like -05:00.
  • The datetime value is for machines; the visible text is for people.