Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 782
Sreenath Plakkat Avatar asked Jan 25 '12 10:01

Sreenath Plakkat


1 Answers

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.

like image 124
Guido Avatar answered Sep 24 '22 10:09

Guido