Java Second timeStringToSeconds(String time)

Here you can find the source of timeStringToSeconds(String time)

Description

time String To Seconds

License

Apache License

Declaration

public static int timeStringToSeconds(String time) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static int timeStringToSeconds(String time) {
        int resultingTime = 0;

        //Removing dots representing milliseconds
        String[] splitString = time.split("\\.");
        if (splitString.length == 0)
            splitString = time.split(":"); // If doesnt contain dots, splits using :
        else/* w  ww  .  j  ava  2  s  .co m*/
            splitString = splitString[0].split(":"); //if contains, get everything before the dot, and splits using :

        if (splitString.length == 3) { // If is in the format HH:mm:ss
            resultingTime += Integer.valueOf(splitString[0]) * 3600;
            resultingTime += Integer.valueOf(splitString[1]) * 60;
            resultingTime += Integer.valueOf(splitString[2]);
        } else if (splitString.length == 2) { //if it's mm:ss
            resultingTime += Integer.valueOf(splitString[0]) * 60;
            resultingTime += Integer.valueOf(splitString[1]);
        } else if (splitString.length == 1) { //Shouldn't ever come to this unless this method is being incorrectly called
            resultingTime += Integer.valueOf(splitString[0]);
        }

        return resultingTime;

    }
}

Related

  1. timeFromSeconds(int timeInSec)
  2. timeFromSeconds(long ms)
  3. timeSpanInSeconds(long time1, long time2)
  4. timeStampSeconds()
  5. timeStringToSeconds(String input)
  6. timeToSeconds(String in)
  7. timeToSeconds(String textTime)
  8. timeToSeconds(String time)
  9. trimMiliSeconds(String time)