THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Time dateTime Property

Time Object Reference Time Object

Example

Get the date that a <time> element represents:

var x = document.getElementById("myTime").dateTime;

The result of x will be:

2014-02-14
Try it yourself »

Definition and Usage

The dateTime property sets or returns the value of the datetime attribute in a <time> element.

The datetime attribute gives the date or time being specified. This attribute is used if no date or time is specified in the element's content.

Note: The datetime attribute does not render as anything special in any of the major browsers.

Note: The <time> element is new in HTML5.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The dateTime property is only supported in Firefox and Opera version 12.

Note: Opera has no longer support for this property, as of version 15.


Syntax

Return the dateTime property:

timeObject.dateTime

Set the dateTime property:

timeObject.dateTime=YYYY-MM-DDThh:mm:ssTZD

Property Values

Value Description
YYYY-MM-DDThh:mm:ssTZD 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 - a required separator 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)

Technical Details

Return Value: A String, representing a machine-readable form of the element's date and time

More Examples

Example

Change the date and time of a <time> element:

document.getElementById("myTime").dateTime = "1999-06-24T09:30Z";
Try it yourself »

Related Pages

HTML reference: HTML <time> datetime attribute


Time Object Reference Time Object