I have an ISO 8601 formatted duration, for eg: PT5M or PT120S.
Is there any way I can parse these using moment.js and fetch the number of minutes specified in the duration?
Thank you!
PS: I looked at Parse ISO 8601 durations and Convert ISO 8601 time format into normal time duration
but was keen to know if this was do-able with moment.
moment does parse ISO-formatted durations out of the box with the moment.duration method:
moment.duration
moment.duration('P1Y2M3DT4H5M6S')
The regex is gnarly, but supports a number of edge cases and is pretty thoroughly tested.
1.4m articles
1.4m replys
5 comments
57.0k users