<time>:(日期)时间元素
<time> HTML 元素代表特定的时间段。它可能包括 datetime 属性,用于将日期转换为机器可读的格式,从而获得更好的搜索引擎结果或自定义功能(例如提醒)。
¥The <time> HTML 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:
Try it
属性
¥Attributes
与所有其他 HTML 元素一样,此元素支持 全局属性。
¥Like all other HTML elements, this element supports the global attributes.
datetime-
该属性指示元素的时间和/或日期,并且必须采用下述格式之一。
使用说明
¥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).
日期时间值(日期时间的机器可读值)是元素的 datetime 属性的值,该属性必须采用正确的格式(见下文)。如果元素没有 datetime 属性,则它不能有任何元素后代,并且日期时间值是元素的子文本内容。
¥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
- 有效的年份字符串
-
2011 - 有效的月份字符串
-
2011-11 - 有效的日期字符串
-
2011-11-18 - 有效的无年份日期字符串
-
11-18 - 有效的周字符串
-
2011-W47 - 有效的时间字符串
-
14:5414:54:3914:54:39.929 - 有效的本地日期和时间字符串
-
2011-11-18T14:54:39.9292011-11-18 14:54:39.929 - 有效的全局日期和时间字符串
-
2011-11-18T14:54:39.929Z2011-11-18T14:54:39.929-04002011-11-18T14:54:39.929-04:002011-11-18 14:54:39.929Z2011-11-18 14:54:39.929-04002011-11-18 14:54:39.929-04:00 - 有效的持续时间字符串
-
PT4H18M3S
示例
简单的例子
datetime 示例
技术总结
规范
| Specification |
|---|
| HTML Standard # the-time-element |
浏览器兼容性
BCD tables only load in the browser
也可以看看
¥See also
<data>元素,允许表示其他类型的值。