jQuery Plugin For Human Readable Date Format - timeAgoInWords.js

File Size: 6.81 KB
Views Total: 1787
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
jQuery Plugin For Human Readable Date Format - timeAgoInWords.js

timeAgoInWords.js is a super lightweight JavaScript library for converting ISO and Unix timestamps into a human readable date format with live update every 60 seconds , e.g. 'x days ago'. Works with or without jQuery library. 

Basic usage:

1. Include the jQuery timeAgoInWords plugin after jQuery JavaScript library like so:

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="time-ago-in-words.js"></script>

2. Wrap the ISO date/time data or UNIX timestamp into an Html element.

<div class="timeago" title="1445668757697">1445668757697</div>
<div class="timeago" title="Sat Oct 26 2015 04:00:01">Sat Oct 26 2015 04:00:01</div>
<div class="timeago" title="2015-12-25 00:00:00 +0800">2015-12-25 00:00:00 +0800</div>
<div class="timeago" title="2014-12-25T00:00:00.037Z">2014-12-25T00:00:00.037Z</div>

3. Just call the plugin and we're done.


4. Use timeAgoInWords.js without jQuery.


5. Default settings.

  refreshMillis: 60000,
  allowPast: true,
  allowFuture: true,
  localeTitle: false,
  cutoff: 0,
  strings: {
    prefixAgo: null,
    prefixFromNow: null,
    suffixAgo: "ago",
    suffixFromNow: "from now",
    inPast: 'any moment now',
    seconds: "less than a minute",
    minute: "about a minute",
    minutes: "%d minutes",
    hour: "about an hour",
    hours: "about %d hours",
    day: "a day",
    days: "%d days",
    month: "about a month",
    months: "%d months",
    year: "about a year",
    years: "%d years",
    wordSeparator: " ",
    numbers: []

This awesome jQuery plugin is developed by perich. For more Advanced Usages, please check the demo page or visit the official website.