Java Second Get getSecondsFromStringDuration(String duration)

Here you can find the source of getSecondsFromStringDuration(String duration)

Description

get Seconds From String Duration

License

Open Source License

Declaration

public static long getSecondsFromStringDuration(String duration) 

Method Source Code

//package com.java2s;

public class Main {

    public static long getSecondsFromStringDuration(String duration) {
        long result = 0;
        String[] tokens = duration.split("[:\\.]");
        int hours = Integer.parseInt(tokens[0]);
        int minutes = Integer.parseInt(tokens[1]);
        int seconds = Integer.parseInt(tokens[2]);
        int tenthMillis = Integer.parseInt(tokens[3]);
        result += hours * 3600;/*from  w w  w .j a  v  a2  s  .com*/
        result += minutes * 60;
        result += seconds;
        if (tenthMillis > 50) {
            result++;
        }
        return result;
    }
}

Related

  1. getSecondsForShortString(String string)
  2. getSecondsFromEpoch()
  3. getSecondsFromHMS(String hmsvalue)
  4. getSecondsFromString(String s)
  5. getSecondsFromString(String text)
  6. getSecondSimpleType(String completeType)
  7. getSecondsInDDHHMMSS(int s)
  8. getSecondsText(long seconds)
  9. getSecondsToHHMMSS(double seconds)