Java Second timeDecimalSeconds(String time)

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

Description

Time converter.

License

Open Source License

Parameter

Parameter Description
time as "hours:minutes:seconds.decimal seconds"

Return

decimal seconds

Declaration

public static double timeDecimalSeconds(String time) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*  w w w.  j a v a 2  s  .  c o  m*/
     * Time converter.
     * @param time as "hours:minutes:seconds.decimal seconds"
     * @return decimal seconds
     */
    public static double timeDecimalSeconds(String time) {
        return timeDecimal(time) * 3600;
    }

    /**
     * Time converter.
     * @param time as "hours:minutes:seconds.decimal seconds"
     * @return decimal hours
     */
    public static double timeDecimal(String time) {
        String[] times = time.split(":");
        if (times.length != 3) {
            return -9999;
        }
        double decimal = Double.parseDouble(times[0]);
        decimal += Double.parseDouble(times[1]) / 60.0;
        decimal += Double.parseDouble(times[2]) / 3600.0;
        return decimal;
    }
}

Related

  1. stringToSeconds(String string)
  2. strTimeToSeconds(String hmsTimes)
  3. ticksToSeconds(long ticks)
  4. ticksWithSecondsSetTo(long ticks, int seconds)
  5. timecents2seconds(int timecents)
  6. timeElapsedSecond(long prevTime, long curTime, long periodSecond)
  7. timeFromSeconds(int timeInSec)
  8. timeFromSeconds(long ms)
  9. timeSpanInSeconds(long time1, long time2)