Today's time in time tag

本小妞迷上赌 提交于 2020-01-23 08:16:06

问题


For date ranges, I currently use this format (until precise specifications come up):

<time datetime="2012-11">November 2012</time> - <time datetime="2013-01">January 2013</time>

I was wondering if there is, or will be, a way to indicate today's date. I mean, I know we can do this:

<time datetime="2013-03-05">Today</time>

but I would like to have something like this:

<time datetime="now">Today</time>

If not, I plan to leave the "Today" word with no extra markup. Would you recommend a better solution?

Thanks!


EDIT: To add bit of context, I am building an online resume, hence the date ranges as well as the ones that involve: <time datetime="yyyy-mm">[Month] [Year]</time> - Present.


回答1:


Thanks everyone for your efforts.

Just to clarify things, I was not looking for ways to dynamically update the content of the datetime attribute. I just wanted to know if there was a way to semantically indicate the "present" day or time.

The answer is: no, there is no way to do that.

I do believe that there might be a change someday. Some of you wondered when this could be useful. I agree that currently there is no need for that, but there might be ways to indicate date ranges in the future specs (the <time> element is still in draft, after all). If so, there could be ranges that start at a precise point and that are still going, giving a use case for a "present"/"now"/... keyword, IMO.




回答2:


Try using php or JavaScript to get the local time from the user's computer, then output that as text. See http://php.net/manual/en/function.localtime.php for instructions on doing it with php.

EDIT: It gets the server time, not the user's time. To get the user's time, you have to use javascript.



来源:https://stackoverflow.com/questions/15223317/todays-time-in-time-tag

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