开发者

jQuery Time Since using HTML5 Time tag

I am looking to implement time since functionality using jQuery. Here are some example dates using the HTML5 time tag and microformat datetime.

    <p><time title="Wednesday, 20 April 2011 at 10:20 am" datetime="2011-04-20T10:20Z00" pubdate>20 April at 10:20 am</time></p>

    <p><time title="Tuesday, 19 April 2011 at 6:22 pm" datetime="2011-04-19T06:22Z00" pubdate>19 April at 6:22 pm</time></p>

    <p><time title="Sunday, 17 April 2011 at 3:18开发者_运维技巧 pm" datetime="2011-04-17T15:13Z00" pubdate>17 April at 3:18 pm</time></p>

    <p><time title="Thursday, 2 December 2010 at 4:32 am" datetime="2010-12-02T00:32Z00" pubdate>2 December at 3:32 pm</time></p>

The idea is that the datetimes within the <time> tags will change to something like 2 minutes ago or Yesterday at 6:22 pm. But for items that are older than a month then they will just stay the same as they are as I have left in a simple date e.g. 2 December at 3:32 pm as a fallback should the user not have JavaScript enabled.

Can anyone help me to build something like this? I've been looking around on the web and found something by John Resig but it would like it to work with the new HTML5 tag and instead of grabbing the info for the title attribute get it from the datetime attribute. Also want it to be in the format I have specified, so instead of just saying Yesterday like his, it would say Yesterday at 6:22 pm. Thanks to all who can help.

Link to resig article: http://ejohn.org/blog/javascript-pretty-date/


Have you looked at the timeago plugin?

It might already do what you want and it supports the HTML5 <time> tag.

HTML5 has a new time tag and timeago supports it too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜