HTML 时间标签 - 正确的日期格式

2022-01-18 00:00:00 time tags html

我想使用正确的格式和标准将时间标签放入我的 html 文档中.

I am wanting to use the correct format and standards to put the time tag in my html document.

这是正确的做法吗?

<time datetime="2014-03-26T12:48:42.733Z">26/03/2014</time>

谢谢

推荐答案

time 在 HTML5 中定义的元素必须以特定的机器可读格式指定时间、日期、时间和日期或其他适用的名称,如草稿.此名称可能显示为元素内容,例如

The time element as defined in HTML5 must specify time, date, time and date, or other applicable designation in a specific machine-readable format, as described in the draft. This designation may appear as the element content, e.g.

<time>2014-03-26></time>

如果不是(通常,当内容以某种语言以人类可读的形式指定日期或时间时),机器可读的指定必须作为 datetime 属性的值出现,例如

If it does not (typically, when the content specifies a date or time in human-readable form in some language), the machine-readable designation must appear as the value of the datetime attribute, e.g.

<time datetime="2014-03-26">26/03/2014</time>

问题中的表示法不充分,因为属性的值必须是以机器可读格式表示的元素内容",而日期和时间表示法,精确到毫秒,很难说表示日期.

The notation in the question is not adequate, as the value of the attribute must be "a representation of the element's contents in a machine-readable format", and a date and time denotation, down to milliseconds, can hardly be said to represent a date.

注意:没有证据表明浏览器或搜索引擎会使用 time 标记,因此此类标记仅具有潜在用途.

Note: There is no evidence of browsers or search engines making any use of time markup, so such markup is only potentially useful.

相关文章