Android Minute to Hour Convert minutesToHuman(int minutes)

Here you can find the source of minutesToHuman(int minutes)

Description

Convert duration in minutes to a more human readable form.

License

MIT License

Parameter

Parameter Description
minutes The duration in minutes

Return

A string on the format "HH:mm"

Declaration

public static String minutesToHuman(int minutes) 

Method Source Code

//package com.java2s;
/**//from w w  w  .  ja  v a  2  s  .  c o  m
 *   DateTimeUtils.java
 *
 *  A utility class for converting dates to common formats
 *
 *   @author Robin Andersson, Johan Brook
 *   @copyright (c) 2012 Robin Andersson, Johan Brook, Mattias Henriksson, Lisa Stenberg
 *   @license MIT
 */

public class Main {
    private final static int HOUR = 60;

    /**
     * Convert duration in minutes to a more human readable form.
     * 
     * @param minutes
     *            The duration in minutes
     * @return A string on the format "HH:mm"
     */
    public static String minutesToHuman(int minutes) {
        int remainingMinutes = minutes % HOUR;
        int hours = minutes / HOUR;

        return hours
                + ":"
                + ((remainingMinutes < 10) ? "0" + remainingMinutes
                        : remainingMinutes);
    }
}