get Chat Time - Android java.util

Android examples for java.util:Time

Description

get Chat Time

Demo Code


//package com.java2s;

public class Main {

    public static String getChatTime(int chatTime) {
        String chatTimeStr;//from w  ww . jav  a2s .c  o m
        String hourStr;
        String minStr;
        String secStr;
        if (chatTime < 1) {
            chatTimeStr = "00:00";
        } else if (chatTime < 10) {
            chatTimeStr = "00:0" + chatTime;
        } else if (chatTime < 60) {
            chatTimeStr = "00:" + chatTime;
        } else if (chatTime < 60 * 60) {
            int min = chatTime / 60;
            int sec = chatTime % 60;

            if (min < 10) {
                minStr = "0" + min;
            } else {
                minStr = "" + min;
            }

            if (sec < 10) {
                secStr = "0" + sec;
            } else {
                secStr = "" + sec;
            }
            chatTimeStr = minStr + ":" + secStr;
        } else {
            long hour = chatTime / 3600;
            long min = chatTime / 60 % 60;
            long sec = chatTime % 60;

            if (min < 10) {
                hourStr = "0" + hour;
            } else {
                hourStr = "" + hour;
            }

            if (min < 10) {
                minStr = "0" + min;
            } else {
                minStr = "" + min;
            }

            if (sec < 10) {
                secStr = "0" + sec;
            } else {
                secStr = "" + sec;
            }
            chatTimeStr = hourStr + ":" + minStr + ":" + secStr;
        }

        return chatTimeStr;
    }
}

Related Tutorials