html5知识点补充—time元素的使用

使用time元素插入日期和时间

使用time元素,我们可以插入计算机能够识别的日期和时间,同时又能以一种可读的方式显示给用户。那么利用此元素,我们不仅可以为内容添加如发布时间、事件发生时间等信息,还可以利用其他的技术(比如说日历系统)。time元素有两个可选属性。

  • datetime: 终端用户浏览的内容在time标记之间,而计算机可以识别datetime值:datetime="2011-04-01T16:00Z"。其中的时间部分(T16:00)是可选的。也可以为其添加时差信息:T16:00+04:00。这里的Z代表的是协调世界时,与添加时差信息+00:00相同。

  • pubdate: pubdate是布尔属性。它代表的是其最近的父article元素内容的发布日期和时间,如没找到任何父article元素,则指向整个文档。每个article元素只能拥有一个带pubdate的time元素。

下面是几个示例:

<body>
    <article>
        <footer>
            <p>This news article was published on <time pubdate datetime="2011-04-01T16:00Z">lst April 2011 at 4pm</time></p>
        </footer>
    </article>

    <article>
        <h1>Christmas day family photo</h1>

        <p>It lovely to have the family here for <time pubdate datetime="2010-12-25">Christmas Day 2010</time></p>
    </article>

    <p>HTML6 release date is due on <time datetime="2040-10-04">Arril 1<sup>st</sup> 2040</time></p>
</body>

猜你喜欢

转载自www.cnblogs.com/baimeishaoxia/p/12669600.html