Java Duration Format formatDuration(final long milliSeconds)

Here you can find the source of formatDuration(final long milliSeconds)

Description

format Duration

License

Open Source License

Parameter

Parameter Description
time in millis

Return

Formatted string without seconds, such as 5:45.

Declaration

public static String formatDuration(final long milliSeconds) 

Method Source Code

//package com.java2s;
// ProjectForge is dual-licensed.

public class Main {
    /**/* w w  w. ja va 2s .co  m*/
     * @return Formatted string without seconds, such as 5:45.
     * @param time in millis
     */
    public static String formatDuration(final long milliSeconds) {
        final long duration = milliSeconds / 60000;
        final long durationHours = duration / 60;
        final long durationMinutes = (duration % 60);
        final StringBuffer buf = new StringBuffer(10);
        buf.append(durationHours);
        if (durationMinutes < 10)
            buf.append(":0");
        else
            buf.append(':');
        buf.append(durationMinutes);
        return buf.toString();
    }
}

Related

  1. formatDuration(Duration duration)
  2. formatDuration(Duration duration, boolean inProgress)
  3. formatDuration(final Duration duration)
  4. formatDuration(final Duration duration, final boolean wrapInDurationFunction)
  5. formatDuration(final int duration)
  6. formatDuration(final long seconds)
  7. formatDuration(int durationMins)
  8. formatDuration(int seconds)
  9. formatDuration(int seconds)