Sreenath Plakkat
Sreenath Plakkat

Reputation: 1785

How to show human-readable "time ago"

My user last logged in at 15:50:09 Wednesday, January 25, 2012 IST how can i show it as "10 minutes ago". Is there any js?

Upvotes: 6

Views: 3241

Answers (1)

Guido
Guido

Reputation: 47665

I have always used timeago, it is a jQuery plugin, very easy to use. The example in the main page is self-explicative:

<script src="jquery.timeago.js" type="text/javascript"></script>
$("abbr.timeago").timeago();

Will convert this markup:

<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>

into this one:

<abbr class="timeago" title="July 17, 2008">3 years ago</abbr>

In some cases is useful to also use datejs, specially if you want to convert dates in a human readable format to a timestamp, but in your case I don't think you really need it.

Upvotes: 10

Related Questions