Java Second Parse parseHHMMSSToSeconds(String txt)

Here you can find the source of parseHHMMSSToSeconds(String txt)

Description

parse HHMMSS To Seconds

License

Open Source License

Declaration

public static double parseHHMMSSToSeconds(String txt) throws Exception 

Method Source Code

//package com.java2s;
/*/* www  . j  a  v  a 2 s  .co m*/
 * Copyright (C) 2012-2015, Juan Manuel Barrios <http://juan.cl/>
 * All rights reserved.
 *
 * This file is part of P-VCD. http://p-vcd.org/
 * P-VCD is made available under the terms of the BSD 2-Clause License.
 */

public class Main {
    public static double parseHHMMSSToSeconds(String txt) throws Exception {
        if (txt.length() == 0)
            return 0;
        String[] tim = txt.split(":");
        if (tim.length == 1)
            return Double.parseDouble(tim[1]);
        else if (tim.length == 2)
            return Integer.parseInt(tim[0], 10) * 60 + Double.parseDouble(tim[1]);
        else if (tim.length == 3)
            return Integer.parseInt(tim[0], 10) * 3600 + Integer.parseInt(tim[1], 10) * 60
                    + Double.parseDouble(tim[2]);
        throw new Exception("invalid time format " + txt);
    }
}

Related

  1. centisecondsPerTick(final int tps)
  2. parseSeconds(String value, int defaultValue)
  3. parseTimeStringAsSeconds(String timeString)
  4. parseW3CDateWithFractionalSeconds(String dateString)