Latest web development tutorials

HTML DOM Time dateTime property

Time Object Reference Time Object

Examples

Get <time> element represents the data:

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

x The output is:

2014-02-14

try it"

Definition and Usage

dateTime property sets or returns the <time> element values ​​in datetime attribute.

datetime attribute specifies the date or time. When the date or time is not specified in the content of the element, the use of the property.

Note: datetime attribute in all browsers do not render any special effects.

Note: <time> element is new in HTML5.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Only Firefox and Opera 12 support dateTime attribute.

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


grammar

Back dateTime attributes:

timeObject .dateTime

Setting dateTime attributes:

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

Property Value

描述
YYYY-MM-DDThh:mm:ssTZD 日期或时间。下面解释了其中的成分:
  • YYYY - 年(例如 2011)
  • MM - 月(例如 01 表示 January)
  • DD - 一个月中的第几天(例如 08)
  • T - 必需的分隔符,若规定时间的话
  • hh - 时(例如 22 表示 10.00pm)
  • mm - 分(例如 55)
  • ss - 秒(例如 03)
  • TZD - 时区标识符(Z 表示祖鲁,也称为格林威治时间)

technical details

return value: A string representation of the computer's date and time elements can handle.


More examples

Examples

Change the <time> element Date and Time:

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

try it"

related articles

HTML Reference Manual: HTML <Time> datetime attribute


Time Object Reference Time Object