HTML5时间标记用法 [英] HTML5 time tag usage

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

问题描述

我可以使用下面的HTML时间标记吗?

Can I use HTML time tag as below?

<time>9:09 PM</time>

我的混淆在于PM,我是否可以这样指定或者时间仅适用于显示24小时制。

My confusion is around the "PM" , whether I can specify it like this OR time is only for displaying 24 hr clock.

推荐答案

根据 W3C对< time> 标记的定义,代表时间的任何内容未指定日期必须是有效的时间字符串,它定义为如下:

According to the W3C definition of the <time> tag, any content which represents a time without specifying also a day must be a valid time-string which it defines as follows:


1.两个ASCII数字,表示小时,范围0≤小时≤23

2.A:(U + 003A)字符

2.A ":" (U+003A) character

3.两个ASCII数字,代表分钟,in范围0≤分钟≤59

3.Two ASCII digits, representing minute, in the range 0 ≤ minute ≤ 59

4.可选(如果秒为非零则需要):

4.Optionally (required if second is non-zero):


1.A:(U + 003A)字符

1.A ":" (U+003A) character

2.两个AS CII数字,表示秒的整数部分,范围0≤s≤59

2.Two ASCII digits, representing the integer part of second, in the range 0 ≤ s ≤ 59

3.可选(如果秒不是整数则需要):

3.Optionally (required if second is not an integer):


1.A 002E FULL STOP字符(。)

1.A 002E FULL STOP character (.)

2.One,two,或三个ASCII数字,代表第二个小数部分

2.One, two, or three ASCII digits, representing the fractional part of second



所以不,12小时的时间格式是非标准的。 HTML5中语义标签的目的是使文档机器可读,这意味着当您希望标签满足其目的时,您需要准确地遵循标准。在这种情况下,标准不允许任何AM或PM。

So no, the 12-hour time format is non-standard. The purpose of the semantic tags in HTML5 is to make the document machine-readable, which means when you want the tags to serve their purpose, you need to follow the standard accurately. In this case the standard does not allow any AM or PM.

然而,当你使用时间标签的 datetime - 属性时,你可以写任何你喜欢的东西文本内容,因为在这种情况下,日期时间将被视为机器可读版本,文本内容将被视为人类可读的版本。所以这个:

However, when you use the datetime-attribute of the time-tag, you can write anything you like into the text content, because in that case the datetime will be considered the machine-readable version and the text-content the human-readable version. So this:

<time datetime="21:09">9:09 PM</time>

有效,所以

<time datetime="21:09">a few minutes past nine in the evening</time>

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

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