time

<time>

 HTML标签(<time>)表示是在24小时的时钟时间或在一个确切的日期公历(带有可选的时间和时区信息)。

内容类别 Flow content, phrasing content, palpable content.
允许的内容 Phrasing content.
标记遗漏没有; 起始和结束标签都是强制性的。
允许的父母任何接受 phrasing content. 的元素。
允许ARIA角色任何
DOM接口 HTMLTimeElement

属性

像所有其他元素一样,此元素拥有可以使用通用属性

datetime该属性表示此元素的时间和日期,并且属性值必须是一个有效的日期格式,并可包含时间。 如果此值不能被解析为日期,元素不会有一个关联的时间戳.

使用说明

此元素用于以机器可读格式显示日期和时间。例如,这可以帮助用户代理提供将事件添加到用户的日历。

该元素不适用于无法计算特定日期的情况,也不适用于引入公历之前的日期(由于计算这些日期的复杂性)。

例子

Simple example

HTML

<p>The concert starts at <time>20:00</time>.</p>

Output

datetime example

HTML

<p>The concert took place on <time datetime="2001-05-15T19:00">May 15</time>.</p>

Output

规范

SpecificationStatusComment
HTML Living StandardThe definition of '<time>' in that specification.Living StandardNo change from HTML 5.1
HTML 5.1The definition of '<time>' in that specification.RecommendationNo change from HTML5
HTML5The definition of '<time>' in that specification.RecommendationInitial definition.

浏览器兼容性

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic Support62(Yes)22No49 11.5 — 127
datetime62(Yes)22No49 11.5 — 127

FeatureAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic Support6262(Yes)22No49 11.5 — 124
datetime6262(Yes)22No49 11.5 — 124