moment-duration

ISO 8601 duration support for Moment.js

npm install moment-duration
2 downloads in the last week
8 downloads in the last month

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.

npm loves you