moment-duration
v0.0.6
Published
ISO 8601 duration support for Moment.js
Downloads
1,646
Readme
moment-duration
ISO 8601 duration support for Moment.js.
Examples
Parsing an ISO 8601 duration string:
var oneWeek = moment.isoDuration('P1W');
var twoDaysThreeHours = moment.isoDuration('P2DT3H');
var fourSeconds = moment.isoDuration('PT4S');
var allMixed = moment.isoDuration('P1Y2M3DT4H5M6S');
The ISO spec for durations doesn't define a millisecond unit, but I consider it useful so added it anyway under the Z
unit.
var twentyMilliseconds = moment.isoDuration('PT20Z');
There's also a helper method to get a duration value in ISO format.
var delay = moment.duration(100);
var isoString = delay.toISOString(duration); // PT100Z
License
moment-duration is freely distributable under the terms of the MIT license.