Calculate The Time Difference And Return A Human-readable Timestamps – time-diff.js

Category: Date & Time , Javascript | December 29, 2018
Author: lecturenotes
Views Total: 201
Official Page: Go to website
Last Update: December 29, 2018
License: MIT

Preview:

Calculate The Time Difference And Return A Human-readable Timestamps – time-diff.js

Description:

time-diff.js is a modern JS library for calculating the time difference and getting human-readable timestamps from any two dates.

How to use it:

Installation.

# Yarn
$ yarn add js-time-diff

# NPM
$ npm install js-time-diff --save

Import the TimeDiff module.

// ES 6
import TimeDiff from 'js-time-diff';

// CommonJS:
const TimeDiff = require('js-time-diff');

Calculate the difference between 2 dates you specify.

// output: 5 days ago
TimeDiff('12-20-18', '12-25-18');

If the second parameter is not provided, it will automatically uses the current local time.

// output: x days ago
TimeDiff('12-20-18');

You Might Be Interested In:


Leave a Reply