Java Time Convert to timeToDouble(Object value)

Here you can find the source of timeToDouble(Object value)

Description

time To Double

License

Apache License

Declaration

public static Double timeToDouble(Object value) 

Method Source Code

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

public class Main {
    public static Double timeToDouble(Object value) {
        Double ret = new Double(0.);
        if (value != null && value instanceof String) {
            //PThhHmmMss.sssS
            try {
                String duration = (String) value;
                int length = duration.length();
                double hours = 0;
                double mins = 0;
                double millisecs = 0.;
                if (length >= 11) {
                    int hPos = duration.indexOf('H');
                    int mPos = duration.indexOf('M');

                    hours = Integer.parseInt(duration.substring(2, hPos));
                    mins = Integer.parseInt(duration.substring(hPos + 1, mPos));
                    millisecs = Double.parseDouble(duration.substring(mPos + 1, length - 1));
                    ret = hours / 24. + mins / 1440. + millisecs / 86400.;
                }/*from w  w w.ja va 2 s  . c  om*/
            } catch (IllegalArgumentException e) {

            }
        }
        return ret;
    }
}

Related

  1. timeToDriveDistanceDeadReckoning(double distance, double robotMaxSpeed, double targetSpeed)
  2. timeToExactString(double d)
  3. timeToFloat(String aTimeDuration)
  4. timeToFromNow(long time)