Convert given time in String format to seconds

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 

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

 

if given time in hours, minuts and seconds then

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

 


Subscribe For Daily Updates

Flutter Questions
Android Questions