Java Minute Format formatMinutes(long timeMinutes)

Here you can find the source of formatMinutes(long timeMinutes)

Description

format Minutes

License

Open Source License

Declaration

public static String formatMinutes(long timeMinutes) 

Method Source Code

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

public class Main {
    public static String formatMinutes(long timeMinutes) {
        long days = timeMinutes / 60 / 24;
        long hours = timeMinutes / 60 % 24;
        long mins = timeMinutes % 60;
        StringBuilder sb = new StringBuilder();
        boolean hasDays = days > 0;
        boolean hasHours = hours > 0;
        boolean hasMins = mins > 0;
        if (hasDays) {
            sb.append(days);/*w ww  .  j a  v a2s.co m*/
            sb.append(" day");
            if (days != 1)
                sb.append('s');
        }
        if (hasHours) {
            if (hasDays) {
                if (hasMins)
                    sb.append(", ");
                else
                    sb.append(" and ");
            }
            sb.append(hours);
            sb.append(" hour");
            if (hours != 1)
                sb.append('s');
        }
        if (hasMins) {
            if (hasDays || hasHours)
                sb.append(" and ");
            sb.append(mins);
            sb.append(" minute");
            if (mins != 1)
                sb.append('s');
        } else {
            if (!(hasMins || hasDays || hasHours))
                return "0 minutes";
        }
        return sb.toString();
    }
}

Related

  1. formatMinutes(double value)
  2. formatMinutes(int minutes)
  3. formatMinutes(long time)
  4. formatMinutes(long time)
  5. formatMinutes(long time, String timerPrecisionId, boolean round)
  6. formatSecondsToMinutes(int secontsTotal)
  7. formatTimeInMinutes(long l)
  8. getFormattedHoursAndMinutes(final long millis)
  9. toReadableMinutes(long time)