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
I have written and used this method to get the actual duration. Hope this helps.
private String parseDuration(String duration) {
duration = duration.contains("PT") ? duration.replace("PT", "") : duration;
duration = duration.contains("S") ? duration.replace("S", "") : duration;
duration = duration.contains("H") ? duration.replace("H", ":") : duration;
duration = duration.contains("M") ? duration.replace("M", ":") : duration;
String[] split = duration.split(":");
for(int i = 0; i< split.length; i++){
String item = split[i];
split[i] = item.length() <= 1 ? "0"+item : item;
}
return TextUtils.join(":", split);
}