Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert ISO 8601 time format into normal time duration

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??

like image 832
user2091061 Avatar asked Sep 30 '13 11:09

user2091061


1 Answers

This seems be not a timeformat, just duration of the video.

     ------ 33 Seconds
    ''
PT1M33S
  '------- 1 Minute

H - Hours
M - Minutes
S- Seconds

So try this

var timeD = "PT1M33S";
var formattedTime = timeD.replace("PT","").replace("H",":").replace("M",":").replace("S","")
alert(formattedTime);

Fiddle for example, can be a done with a simple regex too.

Hope you understand.

like image 194
Praveen Avatar answered Sep 21 '22 15:09

Praveen