jquery.timeago pluginjquery.timeago plugin
Jeff, because Stack Overflow uses jQuery extensively, I recommend the jquery.timeago pluginjquery.timeago plugin.
Benefits:
- Avoid timestamps dated "1 minute ago" even though the page was opened 10 minutes ago; timeago refreshes automatically.
- You can take full advantage of page and/or fragment caching in your web applications, because the timestamps aren't calculated on the server.
- You get to use microformats like the cool kids.
Just attach it to your timestamps on DOM ready:
jQuery(document).ready(function() {
jQuery('abbr.timeago').timeago();
});
This will turn all abbr elements with a class of timeago and an ISO 8601ISO 8601 timestamp in the title:
<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>
into something like this:
<abbr class="timeago" title="July 17, 2008">4 months ago</abbr>
which yields: 4 months ago. As time passes, the timestamps will automatically update.
Disclaimer: I wrote this plugin, so I'm biased.