<time> - HTML: HyperText Markup Language 编辑

The HTML <time> element represents a specific period in time. It may include the datetime attribute to translate dates into machine-readable format, allowing for better search engine results or custom features such as reminders.

It may represent one of the following:

Content categoriesFlow content, phrasing content, palpable content.
Permitted contentPhrasing content.
Tag omissionNone, both the starting and ending tag are mandatory.
Permitted parentsAny element that accepts phrasing content.
Implicit ARIA roleNo corresponding role
Permitted ARIA rolesAny
DOM interfaceHTMLTimeElement

Attributes

Like all other HTML elements, this element supports the global attributes.

datetime
This attribute indicates the time and/or date of the element and must be in one of the formats described below.

Usage notes

This element is for presenting dates and times in a machine readable format. For example, this can help a user agent offer to add an event to a user's calendar.

This element should not be used for dates prior to the introduction of the Gregorian calendar (due to complications in calculating those dates).

The datetime value (the machine-readable value of the datetime) is the value of the element’s datetime attribute, which must be in the proper format (see below). If the element does not have a datetime attribute, it must not have any element descendants, and the datetime value is the element’s child text content.

Valid datetime Values

a valid year string
2011
a valid month string
2011-11
a valid date string
2011-11-18
a valid yearless date string
11-18
a valid week string
2011-W47
a valid time string
14:54
14:54:39
14:54:39.929
a valid local date and time string
2011-11-18T14:54:39.929
2011-11-18 14:54:39.929
a valid global date and time string
2011-11-18T14:54:39.929Z
2011-11-18T14:54:39.929-0400
2011-11-18T14:54:39.929-04:00
2011-11-18 14:54:39.929Z
2011-11-18 14:54:39.929-0400
2011-11-18 14:54:39.929-04:00
a valid duration string
PT4H18M3S

Examples

Simple example

HTML

<p>The concert starts at <time datetime="2018-07-07T20:00:00">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

Specifications

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

Browser compatibility

BCD tables only load in the browser

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

See also

  • The <data> element, allowing to signal other kind of values.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:116 次

字数:8365

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文