datetime-difference
A lightweight module which finds the difference between two dates in the human-friendly format. Works almost exactly like moment's duration(...)
do, but has no dependencies on any libraries — the code is fast and minimal!
Examples
; const date1 = "12/17/2016, 05:23:55 PM";const date2 = "2/21/2017, 07:12:42 AM"; const result = ; /* result is { "years": 0, "months": 2, "days": 3, "hours": 13, "minutes": 48, "seconds": 47, "milliseconds": 0} */ const date3 = "1/1/2016, 00:00:00 AM";const date4 = "1/1/2026, 00:00:00 AM"; const result2 = ; /* result2 is { "years": 10, "months": 0, "days": 0, // 0, because you don't think about leap years as "hours": 0, // well as about daylight time when counting dates! "minutes": 0, "seconds": 0, "milliseconds": 0} */ // Another example: get the result in readable format by parsing the resulting objectconst readme = Object ;// readme is "2 months, 3 days, 13 hours, 48 minutes, 47 seconds" // Yet another example of formatting (using the string-format library as an example):;const string = ;// string is "3 days left"
Installation
The datetime-difference
is shipped in a form of JavaScript module. Install it from npm:
npm install --save datetime-difference