Java Duration Format durationToString(long durationInMillisLong)

Here you can find the source of durationToString(long durationInMillisLong)

Description

duration To String

License

Open Source License

Declaration

public static String durationToString(long durationInMillisLong) 

Method Source Code

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

public class Main {
    public static String durationToString(long durationInMillisLong) {
        double durationInMillis = (double) durationInMillisLong;
        return durationToString(durationInMillis);
    }//from  w  w  w.j av  a 2  s  .c o  m

    public static String durationToString(double durationInMillis) {
        if (durationInMillis < 1000) {
            return String.format("%.3f ms", durationInMillis);
        }

        double durationInSecs = durationInMillis / 1000;
        if (durationInSecs < 60) {
            return String.format("%.3f sec", durationInSecs);
        }

        double durationInMins = durationInSecs / 60;
        if (durationInMins < 60) {
            return String.format("%.3f mins", durationInMins);
        }

        double durationInHours = durationInMins / 60;
        return String.format("%.3f hours", durationInHours);
    }
}

Related

  1. durationToFormattedString(final Duration duration)
  2. durationToSec(int millis)
  3. durationToString(final long msec)
  4. durationToString(int millis)
  5. durationToString(long durationInMilliSeconds)
  6. durationToString(long durationMs)
  7. durationToString(Long ms)
  8. durationToString(long x)
  9. durationTranslator(String sonarDuration)