Java Millisecond Format formatMilliSecondsHumanReadable(long x)

Here you can find the source of formatMilliSecondsHumanReadable(long x)

Description

format Milli Seconds Human Readable

License

Open Source License

Declaration

public static String formatMilliSecondsHumanReadable(long x) 

Method Source Code

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

public class Main {
    public static String formatMilliSecondsHumanReadable(long x) {
        @SuppressWarnings("unused")
        long millis = 0;
        long seconds = 0;
        long minutes = 0;
        long hours = 0;
        long days = 0;

        seconds = (int) (x / 1000);
        millis = x % 1000;//from  ww  w.ja va  2  s .c  o m

        minutes = (int) (seconds / 60);
        seconds = seconds % 60;

        hours = (int) (minutes / 60);
        hours = hours % 60;

        days = (int) (hours / 24);
        days = days % 24;

        String str = seconds + "s";
        /*
         * if (millis >= 100) str += "." + millis; else if (millis >= 10) str +=
         * ".0" + millis; else if (millis >= 1) str += ".00" + millis; str +=
         * " seconds";
         */

        if (minutes > 0)
            str = minutes + "m " + str;
        if (hours > 0)
            str = hours + "h " + str;
        if (days > 0)
            str = days + "d " + str;

        return str;
    }
}

Related

  1. formatMillisAsShortHumanReadablePeriod(long millis)
  2. formatMilliseconds (final long ms)
  3. formatMilliseconds(Double milliseconds)
  4. formatMilliseconds(long milliseconds)
  5. formatMilliseconds(long milliseconds)
  6. formatMillisecondsToConventional(long duration, int unitCount)
  7. formatMillisecondsToConventional(long time)
  8. formatMillisTime(long millis)
  9. formatMillisTimeGMT(long millis)