The question is how to format a JavaScript Date as a string stating the time elapsed similar to the way you see times displayed on Stack Overflow.
e.g.<
I haven't checked (although it wouldn't be hard to), but I think that Stack Exchange sites use the jquery.timeago plugin to create these time strings.
It's quite easy to use the plugin, and it's clean and updates automatically.
Here's a quick sample (from the plugin's home page):
First, load jQuery and the plugin:
Now, let's attach it to your timestamps on DOM ready:
jQuery(document).ready(function() {
jQuery("abbr.timeago").timeago(); });This will turn all
abbrelements with a class oftimeagoand an ISO 8601 timestamp in the title:July 17, 2008into something like this:about a year agowhich yields: about a year ago. As time passes, the timestamps will automatically update.