Java Millisecond Format formatMilliseconds(long milliseconds)

Here you can find the source of formatMilliseconds(long milliseconds)

Description

format Milliseconds

License

Open Source License

Declaration

public static String formatMilliseconds(long milliseconds) 

Method Source Code

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

public class Main {
    public static String formatMilliseconds(long milliseconds) {

        long seconds = milliseconds / 1000;

        if (seconds < 60) {
            return "" + seconds + " second" + s(seconds);
        }//from   ww  w . j a v a2 s.c  o m

        long minutes = seconds / 60;
        seconds = seconds % 60;

        if (minutes < 60) {
            return "" + minutes + " minute" + s(minutes) + " " + seconds + " second" + s(seconds);
        }

        long hours = minutes / 60;
        minutes = minutes % 60;

        if (hours < 24) {
            return "" + hours + " hour" + s(hours) + " " + minutes + " minute" + s(minutes);
        }

        long days = hours / 24;
        hours = hours % 24;

        return "" + days + " day" + s(days) + " " + hours + " hour" + s(hours) + " and " + minutes + " minute"
                + s(minutes);
    }

    private static String s(long quantity) {
        if (quantity == 1) {
            return "";
        } else {
            return "s";
        }
    }
}

Related

  1. formatMillis(String millisecond, String format)
  2. formatMillisAsNumber(long millis)
  3. formatMillisAsShortHumanReadablePeriod(long millis)
  4. formatMilliseconds (final long ms)
  5. formatMilliseconds(Double milliseconds)
  6. formatMilliseconds(long milliseconds)
  7. formatMilliSecondsHumanReadable(long x)
  8. formatMillisecondsToConventional(long duration, int unitCount)
  9. formatMillisecondsToConventional(long time)