I have a duration string \"PT1M33S\". I would like to get result in the following format -> 01:33 Can anyone please tell me how to do so using js or jquery??
I personally use this:
function parseDuration(e){var n=e.replace(/D|H|M/g,":").replace(/P|T|S/g,"").split(":");if(1==n.length)2!=n[0].length&&(n[0]="0"+n[0]),n[0]="0:"+n[0];else for(var r=1,l=n.length-1;l>=r;r++)2!=n[r].length&&(n[r]="0"+n[r]);return n.join(":")}
Same code formatted:
function parseDuration(e){
var n = e.replace(/D|H|M/g,":").replace(/P|T|S/g,"").split(":");
if(1 == n.length)
2!=n[0].length && (n[0]="0"+n[0]),n[0]="0:"+n[0];
else
for(var r=1, l=n.length-1; l>=r;r++)
2!=n[r].length && (n[r]="0"+n[r]);
return n.join(":")
}