get Show Hour Minute English - Android java.util

Android examples for java.util:Minute

Description

get Show Hour Minute English

Demo Code


//package com.java2s;

public class Main {
    public static String getShowHourMinuteEnglish(long timeSecond) {
        if (timeSecond < 60) {
            return timeSecond + "second(s)";
        }/*from  w w  w .j a v a  2 s. c o  m*/
        long hour = timeSecond / 3600;
        long minute = timeSecond / 60 % 60;
        String backStr = "";
        if (hour > 0) {
            backStr = backStr + hour + "hour(s)";
        }

        if (minute > 0) {
            backStr = backStr + minute + "minute(s)";
        }
        return backStr;
    }

    public static String getShowHourMinuteEnglish(long timeSecond,
            boolean shortHand) {
        if (timeSecond < 60) {
            return shortHand ? (timeSecond + "s")
                    : (timeSecond + "second(s)");
        }
        long hour = timeSecond / 3600;
        long minute = timeSecond / 60 % 60;
        String backStr = "";
        if (hour > 0) {
            if (shortHand) {
                backStr = backStr + hour + "h";
            } else {
                backStr = backStr + hour + "hour(s)";
            }
        }

        if (minute > 0) {
            if (shortHand) {
                backStr = backStr + " " + minute + "m";
            } else {
                backStr = backStr + " " + minute + "minute(s)";
            }
        }
        return backStr;
    }
}

Related Tutorials