Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I replace absolute times ("1:30 PM") with relative times ("15 minutes ago") and have them automatically update?

Is there a Javascript script to change the time and date of blogs automaticly like facebook ???

for example "10 minutes ago" instead of "May 15 2010 12:30".

-Thank You

like image 657
acer Avatar asked May 15 '10 01:05

acer


1 Answers

You could use the timeago jQuery plugin; it's a popular way to handle this situation. It will also do the updating for you, if you like, and it supports micro-formatted goodness.

In a nutshell, it turns all abbr elements with an ISO 8601 timestamp into fuzzy timestamps. Thus, if you have

<abbr class="timeago" title="2015-01-10T15:00:00Z">January 10, 2015</abbr>

and the current time is 15:30Z on January 10, 2015, you'll get something like:

<abbr class="timeago" title="2015-01-10T15:00:00Z">30 minutes ago</abbr>

as a result.

like image 98
John Feminella Avatar answered Nov 02 '22 23:11

John Feminella