HTML <time> datetime Attribute

❮ HTML <time> tag

Example

A time element with a machine-readable datetime attribute:

<p>I have a date on <time datetime="2017-02-14">Valentines day</time>.</p>
Try it Yourself »

Definition and Usage

The datetime attribute represent a machine-readable format of a <time> element.

Examples of valid datetime values:

Dates:
<time datetime="1914">  <!-- means the year 1914 -->
<time datetime="1914-12">  <!-- means December 1914 -->
<time datetime="1914-12-20">  <!-- means 20 December 1914 -->
<time datetime="12-20">  <!-- means 20 December any year -->
<time datetime="1914-W15">  <!-- means week 15 of year 1914 -->

Date and Times:
<time datetime="1914-12-20T08:00">  <!-- means 20 December 1914 at 8am -->
<time datetime="1914-12-20 08:00">  <!-- also means 20 December 1914 at 8am -->
<time datetime="1914-12-20 08:30:45">  <!-- with minutes and seconds -->
<time datetime="1914-12-20 08:30:45.687">  <!-- with minutes, seconds, and milliseconds -->

Times:
<time datetime="08:00">  <!-- means 8am -->
<time datetime="08:00-03:00">  <!-- means 8am in Rio de Janeiro (UTC-3 hours)  -->
<time datetime="08:00+03:00">  <!-- means 8am in Madagascar (UTC+3 hours)  -->

Durations:
<time datetime="P2D">  <!-- means a duration of 2 days -->
<time datetime="PT15H10M">  <!-- means a duration of 15 hours and 10 minutes -->

Browser Support

Attribute
datetime 62.0  18.0 22.0 7.0 49.0


Syntax

<time datetime="YYYY-MM-DDThh:mm:ssTZD">

Attribute Values

Value Description
YYYY-MM-DDThh:mm:ssTZD

or

PTDHMS
The date or time being specified. Explanation of components:
  • YYYY - year (e.g. 2011)
  • MM - month (e.g. 01 for January)
  • DD - day of the month (e.g. 08)
  • T or a space - a separator (required if time is also specified)
  • hh - hour (e.g. 22 for 10.00pm)
  • mm - minutes (e.g. 55)
  • ss - seconds (e.g. 03)
  • TZD - Time Zone Designator (Z denotes Zulu, also known as Greenwich Mean Time)
  • P - a prefix for "Period"
  • D - a prefix for "Days"
  • H - a prefix for "Hours"
  • M - a prefix for "Minutes"
  • S - a prefix for "Seconds"

❮ HTML <time> tag
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.