Java Duration Format formatDurationMills(long millis)

Here you can find the source of formatDurationMills(long millis)

Description

Returns a formated string representation of millis .

License

Open Source License

Parameter

Parameter Description
millis the duration to format in milliseconds

Return

a formated string representation of millis

Declaration

public static String formatDurationMills(long millis) 

Method Source Code

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

public class Main {
    /**//from  w ww. j a va 2s.  c om
     * Returns a formated string representation of {@code millis}. Format:
     * HH:MM:SS.
     * 
     * @param millis
     *            the duration to format in milliseconds
     * @return a formated string representation of {@code millis}
     */
    public static String formatDurationMills(long millis) {
        long seconds = millis / 1000;
        long absSeconds = Math.abs(seconds);
        String positive = String.format("%d:%02d:%02d.%03d", absSeconds / 3600, (absSeconds % 3600) / 60,
                absSeconds % 60, millis % 1000);
        return seconds < 0 ? "-" + positive : positive;
    }
}

Related

  1. formatDuration(long t_millis)
  2. formatDuration(long timeInMillis)
  3. formatDurationAsTime(final int duration)
  4. formatDurationHMSms(long ms)
  5. formatDurationLpad(final String s)
  6. formatDurationOneUnit(long milis)
  7. formatHuman(Duration duration)
  8. formatISO8601Duration(int[] t)
  9. formatNanoDuration(final long nanos)