I whipped up a little Javascript library to format relative timestamps. Instead of labelling blog entries something nerdy and confusing like "2005-09-07 08:32 Z", ago lets you say "3 hours ago". You can see it here on my blog. The idea was shamelessly stolen from NetNewsWire, Flickr, and a dozen other apps. I implemented it here on my blog to help me deal with time zones; I'm in Zürich, my server is in Texas but running in UTC, and most of my friends are in California.

To use it, put some javascript in your document like

It will be replaced with a friendly English string in the client's browser. The number is a Unix seconds since epoch timestamp. The clever thing here is that by doing this in Javascript, the relative timestamps look correct even if the page is pulled from a cache. (It will be broken if the client's clock is wrong, but that's their problem.)

The code is freely available, public domain. You'll also find JsUnit tests, a demo, and a Blosxom plugin to make it easy to add to my blog.

  2005-09-08 06:50 Z