How to convert Youtube API V3 duration in Java

前端 未结 15 2007
梦如初夏
梦如初夏 2021-02-07 03:39

The Youtube V3 API uses ISO8601 time format to describe the duration of videos. Something likes \"PT1M13S\". And now I want to convert the string to the number of seconds (for

15条回答
  •  无人共我
    2021-02-07 03:47

    Time is already formatted, so it seems just replacing will be enough.

     private String stringForTime(String ytFormattedTime) {
                     return ytFormattedTime
                            .replace("PT","")
                            .replace("H",":")
                            .replace("M",":")
                            .replace("S","");
     }
    

提交回复
热议问题