Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
84
rated 0 times [  87] [ 3]  / answers: 1 / hits: 22592  / 10 Years ago, fri, january 9, 2015, 12:00:00

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.


More From » momentjs

 Answers
7

moment does parse ISO-formatted durations out of the box with the moment.duration method:


moment.duration('P1Y2M3DT4H5M6S')

The regex is gnarly, but supports a number of edge cases and is pretty thoroughly tested.


[#68272] Tuesday, January 6, 2015, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
clarkulisesa

Total Points: 422
Total Questions: 93
Total Answers: 112

Location: Austria
Member since Thu, Jan 7, 2021
3 Years ago
clarkulisesa questions
Mon, Feb 24, 20, 00:00, 4 Years ago
Mon, Aug 12, 19, 00:00, 5 Years ago
;