1.0.0 • Published 5 years ago

js-time-diff v1.0.0

Weekly downloads
34
License
MIT
Repository
github
Last release
5 years ago

Javascript Time Difference Library

An extremely lightweight time difference javascript library.

Install

// npm
npm i js-time-diff

// yarn
yarn add js-time-diff

Usages

Use in HTML
<script type="text/JavaScript" src="dist/time-diff.min.js" />

//use global variable TimeDiff
Or use in javascript
import TimeDiff from 'js-time-diff'; //es6

var TimeDiff = require('js-time-diff'); //es5

Example

TimeDiff('07-07-18', '07-10-18');
// output: 3 days ago

//the second parameter is the current date and time by default.
TimeDiff('07-07-18'); 
// output: 9 days ago

TimeDiff('Sun Jul 15 2018 16:01:07 GMT+0530');
// output: 31 seconds ago

TimeDiff('Sun Jul 15 2018 16:01:07 GMT+0530', 'Sun Jul 15 2018 16:02:55 GMT+0530');
// output: 2 minutes ago

TimeDiff('Sun Jul 15 2018 16:01:07 GMT+0530', new Date() );
// output: 2 days ago