How do you markup a date range with the HTML5 time tag?

匿名 (未验证) 提交于 2019-12-03 02:45:02

问题:

When marking-up dates in HTML5, I know for a single date you should use the <time> tag as follows

<time datetime="2011-04-02">2nd April 2011</time>

But how would you (or should you) markup a date range like "2nd - 4th April 2011"?

Thanks.

回答1:

It would be nice if <time> had a nice way of representing ranges, but you have to do something like this instead:

<time datetime="2011-04-02">2nd</time> - <time datetime="2011-04-04">4th April 2011</time> 


回答2:

Marking up date ranges has yet to be settled at this point. (You can see the evolving discussion on date ranges on the WhatWG site.)

Your best bet for now is to simply use the ISO 8601 syntax for date ranges as the datetime value in a time tag. In short, just separate the two values with a forward slash.

For example, the 2nd to the 4th of April, 2011 would be:

<time datetime="2011-04-02/2011-04-04">2nd&ndash;4th April 2011</time> 

Here's a simpler example representing 2000-2010:

<time datetime="2000/2010">2000&ndash;2010</time> 

Remember to use an En dash between your dates for proper presentation.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!