Author: | yairEO |
---|---|
Views Total: | 441 views |
Official Page: | Go to website |
Last Update: | April 20, 2021 |
License: | MIT |
Preview:

Description:
A lightweight (less than 1kb), standalone relative time JavaScript library that converts timestamps to human-readable time format such as “5 mins ago”, “in 7 days”, and so on.
How to use it:
1. Install and import the relative-time.js.
# NPM
$ npm i @yaireo/relative-time
import RelativeTime from ‘@yaireo/relative-Time’
2. Or load the relative-time.js JavaScript library in the document.
<script src=”relative-time.min.js”></script>
3. Initialize the relative-time.js.
const relativeTime = new RelativeTime();
4. Custom local is supported as well.
const relativeTimeSpanish = new RelativeTime({ locale: 'fr' });
5. Convert timestamps to relative time as follows:
relativeTime.from(new Date('10/20/1984')) => 37 years ago