Java Millisecond Convert millisToShortDHMS(long duration)

Here you can find the source of millisToShortDHMS(long duration)

Description

converts time (in milliseconds) to human-readable format "hh:mm:ss"

License

Open Source License

Declaration

public static String millisToShortDHMS(long duration) 

Method Source Code

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

public class Main {
    public final static long ONE_SECOND = 1000;
    public final static long SECONDS = 60;
    public final static long MINUTES = 60;
    public final static long HOURS = 24;

    /**//from   ww  w  .j  av  a2  s .com
     * converts time (in milliseconds) to human-readable format
     *  "<dd:>hh:mm:ss"
     */
    public static String millisToShortDHMS(long duration) {
        String res = "";
        duration /= ONE_SECOND;
        int seconds = (int) (duration % SECONDS);
        duration /= SECONDS;
        int minutes = (int) (duration % MINUTES);
        duration /= MINUTES;
        int hours = (int) (duration % HOURS);
        int days = (int) (duration / HOURS);
        if (days == 0) {
            res = String.format("%02d:%02d:%02d", hours, minutes, seconds);
        } else {
            res = String.format("%dd%02d:%02d:%02d", days, hours, minutes, seconds);
        }
        return res;
    }
}

Related

  1. millisToSecond(long millisecond)
  2. millisToSeconds(final long millis)
  3. millisToSeconds(long millis)
  4. millisToSeconds(long millis)
  5. millisToSeconds(long millis)
  6. millisToString(float millis)
  7. millisToString(long millis)
  8. millisToString(long ms)
  9. millisToString(long t)