This is a library for dealing with durations. It works well with javascript's Date objects.
Note: For compatibility with Go's time.Duration
use the golang_compatible branch.
$ npm install duration-js
var Duration = ;
Parse
ms
- milliseconds
- secondm
- minuteh
- hourd
- dayw
- week
var d = "6w5d4h3m2s1ms";console;
Format
console; // => "str: 1h ms: 3600000"
Basic Operations
// Additionvar d1 = "6d"d2 = d1 + Durationday;console // => "168h"// Multiplicationvar d3 = "5m"d4 = d3 * 12;console // => "1h"// etc ...
Dates
// Adding duration to datevar d = Durationnow =later = now + d;console;// Duration between two datesvar bday = "March 3, 1991"now =age = now - bday;console;
setTimeout / setInterval
;;