We can convert given time to seconds in different formats here we acan find below way if the given time is minuts and seconds string then if given time in hours, minuts and seconds then
String time = "11:12"; //mm:ss
String[] timeinArray= time.split(":"); //will break the string up into an array
int minutes = Integer.parseInt(timeinArray[0]); //first element
int seconds = Integer.parseInt(timeinArray[1]); //second element
int duration = 60 * minutes + seconds; //add up our values
String time = "01:11:12"; //hh:mm:ss
String[] timeinArray= time.split(":"); //will break the string up into an array int
int hours = Integer.parseInt(timeinArray[0]); //first element int
int minutes = Integer.parseInt(timeinArray[1]); //second element
int seconds = Integer.parseInt(timeinArray[2]); //third element
int duration = 60 *60 * hours+60 * minutes + seconds; //add up our values
What is Instance variable?
Can we declare the main () method as final in Java?
Can we declare a static variable within a method in java?
What are the important features of Java 8?
How to check Java version?
Memory Allocation in Java
Can we define a static constructor in Java?
Can we overload the main method in Java?
Convert given time in String format to seconds
Can we declare the main method as private in Java?
What is Method Overloading in Java ?
What is a Class/Static Variables?
How to Create Objects in Java?
How to create a table in Java with JDBC Connection?
What is the Difference between Path and ClassPath in java?
What is the difference between JDK and JRE?