72

I have been going through some tutorials on the <time> tag, but I honestly don't see why we are using it.

For example:

Published <time pubdate datetime="2011-07-03">07/03</time>

If we are going to have a string 07/03 anyway, what is the purpose of using a time tag? It doesn't validate anything.

Anders
  • 8,307
  • 9
  • 56
  • 88
CppLearner
  • 16,273
  • 32
  • 108
  • 163

4 Answers4

67

The point of this tag, as with a number of the new "semantic" HTML5 tags, is to make it easier for programs to index your data.

A script can go through and easily find out what the published date is for your blog articles if it sees a <time> tag, without having to parse any of a number of ways this could be represented (for consumption by a human being), which would be a much more complex and error-prone task.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
Jeremy Roman
  • 16,137
  • 1
  • 43
  • 44
52

It's in a machine-readable format, so any script or search engine reading your content can understand the date/time of publication. That way you can format it in a nice way for readers without affecting machine readability. It's covered under microformats which are a good thing.

E.g. <time pubdate datetime="2011-07-03">3 days ago</time> looks nice for humans and computers.

Tak
  • 11,428
  • 5
  • 29
  • 48
17

HTML5 time element

When in doubt look at the spec!

The time element represents its contents, along with a machine-readable form of those contents in the datetime attribute. The kind of content is limited to various kinds of dates, times, time-zone offsets, and durations, as described below.

From the HTML5.2 spec on the W3C site: https://www.w3.org/TR/html52/textlevel-semantics.html#the-time-element

Have a look at the site for more info. :)

Deilan
  • 4,740
  • 3
  • 39
  • 52
Alerty
  • 5,945
  • 7
  • 38
  • 62
4

The time element also has an associated DOM API that can be used. See http://my.opera.com/ODIN/blog/2011/05/31/dom-scripting-and-the-time-element and http://www.whatwg.org/specs/web-apps/current-work/multipage/text-level-semantics.html#the-time-element

Divya Manian
  • 1,927
  • 11
  • 16