Time dateTimeProperty

Time 对象参考手册Time Object

Example

Get the data represented by the <time> element:

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

xThe output result is:

2014-02-14

Try it Yourself »

Definition and Usage

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

The datetime attribute specifies a date or time. This attribute is used when the date or time is not specified in the content of the element.

Note:The datetime attribute does not render any special effect in any browser.

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


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Only Firefox and Opera 12 support the dateTime property.

Note:Since version 15, Opera no longer supports this property.


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 Date or time. The components are explained below:
  • 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 specified
  • hh - hour (e.g., 22 for 10.00pm)
  • mm - minutes (e.g., 55)
  • ss - seconds (e.g., 03)
  • TZD - time zone designator (Z for Zulu, also known as Greenwich Mean Time)

Technical Details

Return Value: A string, representing the date and time of the element in a computer-processable form.


More Examples

Example

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

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

Try it Yourself »

Related Articles

HTML Reference Manual:HTML <time> datetime Attribute


Time 对象参考手册Time Object

Other Extensions