L
L
Leks22019-04-11 13:00:30
Java
Leks2, 2019-04-11 13:00:30

Convert youtube video time?

I got the time of the youtube video, via Json PT24M30S, can I translate it somehow, is this time in seconds?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
keeplod, 2019-04-11
@keeplod

You can use a regular expression and remove non-digits.
str = "PT1H24M30S";
str = str.replaceAll("\\D+","");
After converting to seconds
or you can do this:
int PT = 0;//days
int HH = 0; //hours
int MM = 0;//minutes
int SS = 0;//seconds
check the first character of the string "PT1H24M30S"
str = "PT1H24M30S";
char ch = str.charAt(0);
if (ch == "P") {
if(str.charAt(3).isDigit()){ //if the fourth character is a digit
TT = str.charAt(2) + str.charAt(3)
}else (PT = str.charAt(2))
//and delete in the line PT1H24M30S PT1 is no longer useful, and then again you run it by the clock and id
}
and check if there is P then 2 and 3 (if it is a digit) the symbol of this line is hours
, we also do minutes and seconds

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question