Java Second Convert toSeconds(long millis)

Here you can find the source of toSeconds(long millis)

Description

to Seconds

License

Open Source License

Declaration

public static String toSeconds(long millis) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String toSeconds(long millis) {
        return toString(millis, "s");
    }//from  ww w  .j a va  2s  . c  om

    public static String toString(long millis, String unit) {
        double factor = getFactor(unit);
        return ((double) millis) / factor + unit;
    }

    private static long getFactor(String value) {
        long factor = 0;
        if (value.endsWith("ms")) {
            factor = 1;
        } else if (value.endsWith("s")) {
            factor = 1000;
        } else if (value.endsWith("m")) {
            factor = 1000 * 60;
        } else if (value.endsWith("h")) {
            factor = 1000 * 60 * 60;
        } else if (value.endsWith("d")) {
            factor = 1000 * 60 * 60 * 24;
        }
        return factor;
    }
}

Related

  1. toDaySecondDifference(long difference)
  2. toHhMmSs(long seconds)
  3. toNanoseconds(long sec, long nanos)
  4. toSeconds(double value)
  5. toSeconds(long date)
  6. toSeconds(long milliseconds)
  7. toSeconds(long nanoseconds)
  8. toSeconds(long nanoSeconds)
  9. toSecondsPrecisionInMs(long ms)