持续时间的HTML时间标记 [英] HTML time tag for duration

查看:485
本文介绍了持续时间的HTML时间标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示视频的持续时间。我应该使用< time> 还是仅用于显示时钟中的时间?

I need to display the duration of a video. Should I use <time> or should it be used only for displaying time as in a clock?

示例

这是正确的HTML5吗?

Is this correct HTML5?

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

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

Or should <time> be used only on a situation like this?

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

文档

MDN 提出以下定义:


HTML元素表示24小时制的时间或公历中的精确日期(带有可选的时间和时区信息)。
此元素旨在用于以机器可读格式显示日期和时间。这有助于用户代理为用户的日历提供任何事件安排。

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 有些不同,它指的是持续时间:

However, the definition in W3C is somewhat different, and it refers duration:


指定日期或时间该元素代表。

Specifies the date or time that the element represents.

价值:以下任何一项:


  • (...)

  • (...)

[HTML5]规范中定义的有效持续时间字符串

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

示例:

PT4H18M3S

4h 18m 3s


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

So, I'm not sure if I should be using <time> in this situation or not. Any thoughts?

推荐答案

是的,你可以使用 时间元素持续时间。

Yes, you can use the time element for durations.

但该值必须是有效的持续时间字符串,3:30 min不是。

But the value has to be a valid duration string, which "3:30 min" is not.

你可以使用 datetime 属性指定正确的值,并将3:30 min保留为元素内容,例如:

You can use the datetime attribute to specify the correct value, and keep "3:30 min" as element content, e.g.:

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

这篇关于持续时间的HTML时间标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆