Skip to content

Instantly share code, notes, and snippets.

@Tenderfeel
Created November 8, 2017 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tenderfeel/e6a3cfa278ed46fb2b32e86050fa6a0c to your computer and use it in GitHub Desktop.
Save Tenderfeel/e6a3cfa278ed46fb2b32e86050fa6a0c to your computer and use it in GitHub Desktop.
ISO_8601 Durations(time) convert
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;
}
@Tenderfeel
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment