Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question