项目作者: lecturenotes

项目描述 :
An extremely lightweight time difference JavaScript library.
高级语言: JavaScript
项目地址: git://github.com/lecturenotes/js-time-diff.git
创建时间: 2018-07-01T15:56:35Z
项目社区:https://github.com/lecturenotes/js-time-diff

开源协议:

下载


Javascript Time Difference Library

An extremely lightweight time difference javascript library.

Install

  1. // npm
  2. npm i js-time-diff
  3. // yarn
  4. yarn add js-time-diff

Usages

Use in HTML
  1. <script type="text/JavaScript" src="dist/time-diff.min.js" ></script>
  2. //use global variable TimeDiff
Or use in javascript
  1. import TimeDiff from 'js-time-diff'; //es6
  2. var TimeDiff = require('js-time-diff'); //es5

Example

  1. TimeDiff('07-07-18', '07-10-18');
  2. // output: 3 days ago
  3. //the second parameter is the current date and time by default.
  4. TimeDiff('07-07-18');
  5. // output: 9 days ago
  6. TimeDiff('Sun Jul 15 2018 16:01:07 GMT+0530');
  7. // output: 31 seconds ago
  8. TimeDiff('Sun Jul 15 2018 16:01:07 GMT+0530', 'Sun Jul 15 2018 16:02:55 GMT+0530');
  9. // output: 2 minutes ago
  10. TimeDiff('Sun Jul 15 2018 16:01:07 GMT+0530', new Date() );
  11. // output: 2 days ago