Converts seconds into hours and minutes. - Android java.util

Android examples for java.util:Second

Description

Converts seconds into hours and minutes.

Demo Code


//package com.java2s;

public class Main {
    /**//from www . j  av  a  2 s .  c o  m
     * Converts seconds into hours and minutes. 
     * 
     * @param seconds - time in seconds 
     * @return String - in the form of <hours>h <minutes>min
     */
    public static String formatSecondsToHHMM(long seconds) {
        long m = (seconds / 60) % 60;
        long h = (seconds / 60) / 60;
        String hhmm = "";

        if (h > 0) {
            hhmm += h + "h";
        }
        if (m > 0) {
            hhmm += " ";
            hhmm += m + "min";
        }
        if (hhmm.length() < 1) {
            hhmm += "1min";
        }
        return hhmm;
    }
}

Related Tutorials