Java Duration Format formatDuration(long milliseconds)

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

Description

format Duration

License

Apache License

Declaration

public static String formatDuration(long milliseconds) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String formatDuration(long milliseconds) {
        int s = (int) (milliseconds / 1000);
        milliseconds = milliseconds % 1000;

        int m = s / 60;
        s = s % 60;/*from w w  w . j a va  2 s. c  o  m*/

        int h = m / 60;
        m = m % 60;

        return padWithLeadingZeros(h, 2) + ":" + padWithLeadingZeros(m, 2) + ":" + padWithLeadingZeros(s, 2) + "."
                + padWithLeadingZeros((int) milliseconds, 3);
    }

    public static String padWithLeadingZeros(int n, int minLength) {
        return padWithLeadingZeros("" + n, minLength);
    }

    public static String padWithLeadingZeros(String s, int minLength) {
        while (s.length() < minLength)
            s = "0" + s;
        return s;
    }
}

Related

  1. formatDuration(Long input)
  2. formatDuration(long milis)
  3. formatDuration(long millis)
  4. formatDuration(long millis)
  5. formatDuration(long milliseconds)
  6. formatDuration(long ms)
  7. formatDuration(long ms)
  8. formatDuration(long number)
  9. formatDuration(long seconds)