Java Minute Format getFormattedHoursAndMinutes(final long millis)

Here you can find the source of getFormattedHoursAndMinutes(final long millis)

Description

get Formatted Hours And Minutes

License

Open Source License

Parameter

Parameter Description
millis a parameter

Return

hours:minutes (e. g. 2:30, 12:30, 127:15, ...)

Declaration

public static String getFormattedHoursAndMinutes(final long millis) 

Method Source Code

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

public class Main {
    /**/*w w  w  .  java  2s . c o  m*/
     * @param millis
     * @return hours:minutes (e. g. 2:30, 12:30, 127:15, ...)
     */
    public static String getFormattedHoursAndMinutes(final long millis) {
        final long seconds = millis / 60000;
        final int hours = (int) seconds / 60;
        final int minutes = (int) seconds % 60;
        final StringBuilder buf = new StringBuilder();
        buf.append(hours).append(":"); // hours
        formatNumber(buf, minutes); // minutes
        return buf.toString();
    }

    private static void formatNumber(final StringBuilder buf, final long number) {
        if (number < 10) {
            buf.append("0");
        }
        buf.append(number);
    }
}

Related

  1. formatMinutes(long time)
  2. formatMinutes(long time, String timerPrecisionId, boolean round)
  3. formatMinutes(long timeMinutes)
  4. formatSecondsToMinutes(int secontsTotal)
  5. formatTimeInMinutes(long l)
  6. toReadableMinutes(long time)