Convert ISO 8601 time format into normal time duration

前端 未结 4 573
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 15:36

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

4条回答
  •  孤独总比滥情好
    2021-01-12 16:20

    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.

提交回复
热议问题