Given a specific DateTime
value, how do I display relative time, like:
Jeff, because Stack Overflow uses jQuery extensively, I recommend the jquery.timeago plugin.
Benefits:
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 8601 timestamp in the title:
July 17, 2008
into something like this:
4 months ago
which yields: 4 months ago. As time passes, the timestamps will automatically update.
Disclaimer: I wrote this plugin, so I'm biased.