Created
November 8, 2017 05:51
-
-
Save Tenderfeel/e6a3cfa278ed46fb2b32e86050fa6a0c to your computer and use it in GitHub Desktop.
ISO_8601 Durations(time) convert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function duration(str) { | |
var matches = str.match(/PT(\d*)H*(\d+)M*(\d+)S*/i); | |
var d = (matches[1] && matches[1] + ':'); //hour | |
d += (matches[1] && matches[2] < 10 ? '0' : '') + (matches[2] && matches[2] + ':'); //min | |
d += (matches[3] && matches[3] < 10 ? '0' : '') + (matches[3] && matches[3]); //sec | |
return d; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://en.wikipedia.org/wiki/ISO_8601#Durations