Tiny Relative Time (Timeago) JavaScript Library – Lately.js

Category: Date & Time , Javascript | May 2, 2022
Author:Tokinx
Views Total:73 views
Official Page:Go to website
Last Update:May 2, 2022
License:MIT

Preview:

Tiny Relative Time (Timeago) JavaScript Library – Lately.js

Description:

Lately.js is a super tiny (~ 1kb) and blazing fast timeago library that automatically shortens the Datetime (ISO 8601) into relative time (how long ago).

How to use it:

1. Load the minified version of the Lately.js library in the document.

<script src="lately.js"></script>

2. Add your Datetime string (ISO 8601) to the page.

// time tag
<time class="lately" datetime="2016-09-28T23:49:41+00:00" itemprop="datePublished" pubdate>2016-September-28</time>
// title attribute
<a href="#" class="lately" title="2020-02-14 18:56">Any string</a>
// OR any container element
<a href="#" class="lately">2021-02-12 21:39</a>

3. Initialize the Lately.js. That’s it.

window.Lately && Lately.init({ 
  target: '.lately'
});

4. Localize the Lately.js library.

window.Lately && Lately.init({ 
  target: '.lately',
  lang: {
    'second': ' Second',
    'minute': ' Minute',
    'hour': ' Hour',
    'day': ' Days',
    'month': ' Month',
    'year': ' Years',
    'ago': ' Ago',
    'error': 'NaN'
  }
});

You Might Be Interested In:


Leave a Reply