@SuppressWarnings("UnusedDeclaration")
    public static String formatTime(long timeInMilli) {
        long hourBasis = 60;

        StringBuilder formattedTime = new StringBuilder();

        long secTmp = timeInMilli / 1000;
        long sec = secTmp % hourBasis;
        long minTmp = secTmp / hourBasis;
        long min = minTmp % hourBasis;
        long hour = minTmp / hourBasis;

        if (hour > 0) {
            formattedTime.append(hour).append(" hour");
            if (hour > 1)
                formattedTime.append("s");
        }

        if (min > 0) {
            if (formattedTime.length() > 0)
                formattedTime.append(", ");
            formattedTime.append(min).append(" minute");
            if (min > 1)
                formattedTime.append("s");
        }

        if (sec > 0) {
            if (formattedTime.length() > 0)
                formattedTime.append(", ");
            formattedTime.append(sec).append(" second");
            if (sec > 1)
                formattedTime.append("s");
        }

        if (formattedTime.length() > 0)
            return formattedTime.toString();

        return "< 1 second";
    }
@ SuppressWarnings ( "UnusedDeclaration" ) public static String formatTime ( long timeInMilli ) { long hourBasis = 60 ; StringBuilder formattedTime = new StringBuilder ( ) ; long secTmp = timeInMilli / 1000 ; long sec = secTmp % hourBasis ; long minTmp = secTmp / hourBasis ; long min = minTmp % hourBasis ; long hour = minTmp / hourBasis ; if ( hour > 0 ) { formattedTime . append ( hour ) . append ( " hour" ) ; if ( hour > 1 ) formattedTime . append ( "s" ) ; } if ( min > 0 ) { if ( formattedTime . length ( ) > 0 ) formattedTime . append ( ", " ) ; formattedTime . append ( min ) . append ( " minute" ) ; if ( min > 1 ) formattedTime . append ( "s" ) ; } if ( sec > 0 ) { if ( formattedTime . length ( ) > 0 ) formattedTime . append ( ", " ) ; formattedTime . append ( sec ) . append ( " second" ) ; if ( sec > 1 ) formattedTime . append ( "s" ) ; } if ( formattedTime . length ( ) > 0 ) return formattedTime . toString ( ) ; return "< 1 second" ; }
Formats a time given in millisecond. The output will be "X hours Y min Z sec", unless X, Y or Z is 0 in which
case that part of the string will be omitted.
<p/>
Created on May 3, 2004 by Fabian Depry
@param timeInMilli time in milli-seconds
@return a <code>String</code> representing the formatted time...