HTML 持续时间的时间标签

HTML time tag for duration

我需要显示视频的时长。我应该使用 <time> 还是应该像时钟一样仅用于显示时间?

例子

这是否正确 HTML5?

<p>Duration: <time>3:30 min</time>.</p>

或者 <time> 应该只在这种情况下使用?

<p>Good morning. The actual time is: <time>9:45</time></p>.

文档

MDN 给出以下定义:

The HTML element represents either a time on a 24-hour clock or a precise date in the Gregorian calendar (with optional time and timezone information). This element is intended to be used presenting dates and times in a machine readable format. This can be helpful for user agents to offer any event scheduling for user's calendar.

不过W3C中的定义有些不同,指的是时长:

Specifies the date or time that the element represents.

Value: Any one of the following:

  • (...)

  • a valid duration string as defined in the [HTML5] specification

Examples:

PT4H18M3S

4h 18m 3s

所以,我不确定在这种情况下是否应该使用 <time>。有什么想法吗?

如果规范允许 time 元素具有持续时间作为值,则意味着它可以这样使用。我在规范中发现的唯一 limitation 是您不能指定月或年的持续时间 — 只能指定周、天、小时、分钟和秒。但在视频的持续时间内应该不是问题)。

是的,您可以使用 time element 持续时间。

但该值必须是 valid duration string,而“3:30 分钟”不是。

您可以使用datetime attribute指定正确的值,并保留“3:30 min”作为元素内容,例如:

<time datetime="3m 30s">3:30 min</time>