This course will become read-only in the near future. Tell us at community.p2pu.org if that is a problem.

Time [Nov. 22, 2011, 11:36 p.m.]


We frequently describe events in our daily communications. As humans, we can easily interpret statements such as 'would you like to hang out tonight?' or 'my birthday is 1/7/81.' These statements are ambiguous on a couple of levels. First, 'today' is constantly changing. An event taking place 'today' quickly becomes yesterday's news. The second example even gives us humans difficulty. Is the date July 1st, 1981 or January 7th 1981?

HTML5 provides us with a tag to explicitly convey dates and times. The tag, as with most HTML tags, is appropriately named:

  • <time>

The <time> tag has an attribute called datetime. The datetime attribute takes a specifically formatted string:

YYYY-MM-DDTHH:MMTZO
YYYY = four digit year
MM = two digit month, zero padded if necessary
DD = two digit day, zero padded if necessary
T = time separator, do not change
HH = hour, 24 hour (e.g. 13 = 1PM), zero padded if necessary
MM = minute, two digits
TZO = timezone offset, +/- 23:59 (typically whole hour offset)

An example of a specific event would be August, 21st, 1999 355PM GMT -8:

<time datetime="1999-08-21T15:55-08">

The <time> tag also has a boolean attribute called pubdate. When pubdate is present in a <time> tag, the event is taken to be the publishing date of the parent element (such as an <article>.)

The time format adheres to a convention, designated by the International Standards Organization, called ISO 8601:

The standard organizes the data so the largest temporal term (the year) appears first in the data string and progresses to the smallest term (the second). It also provides for a standardized method of communicating time-based information across time zones by attaching an offset to Coordinated Universal Time (UTC).