Time difference in words: jQuery fuzzy timestamps plugin – timeago

Show time difference in words with timeago – a jQuery fuzzy timestamps plugin.

The “timeago” plugin – jQuery fuzzy timestamps

A jQuery plugin that makes it easy to support automatically updating fuzzy timestamps, for example:

“5 minutes ago

“You opened this page 15 minutes ago”

“Commented 2 hours ago”

“He was born 44 years ago”

etc.

We can take full advantage of page caching in web applications, because the timestamps aren’t calculated on the server.

jQuery timeago plugin - time difference in words
jQuery timeago plugin – time difference in words

Usage

We get to use standard HTML5 tags. First, load jQuery and the plugin:

<script src="jquery.min.js" type="text/javascript"></script>
<script src="jquery.timeago.js" type="text/javascript"></script>

Start the plugin:

jQuery(document).ready(function() {
  jQuery("time.timeago").timeago();
});

This will turn all time elements with a class of timeago and an ISO 8601 timestamp in the datetime:

<time class="timeago" datetime="2009-07-17T09:24:17Z">
  July 17, 2009
</time>

We can also use it programmatically:

jQuery.timeago(new Date());             //=> "less than a minute ago"
jQuery.timeago("2008-07-17");           //=> "8 years ago"
jQuery.timeago(jQuery("time#some_id")); //=> "8 years ago"
                                        // [title="2008-07-20"]

License: MIT

Docs and examples @ project homepage:

http://timeago.yarp.com

Get jQuery fuzzy timestamps plugin from GitHub:

https://github.com/rmm5t/jquery-timeago

See also:

jQuery countdown timer plugins

Analog and digital jQuery world clock plugin – jClocksGMT.js

A simple jQuery number counter plugin – counter.js

Material time picker library – a timer picker written in ES6 and SASS

Enjoy!

Share:Share on Facebook1Share on Google+0Tweet about this on TwitterShare on LinkedIn1Pin on Pinterest0