format Long To Time String - Android java.util

Android examples for java.util:Date Convert

Description

format Long To Time String

Demo Code

import android.annotation.SuppressLint;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Main{

    public static String formatLongToTimeStr(Long l) {
        String str = "";
        int hour = 0;
        int minute = 0;
        int second = 0;
        second = l.intValue() / 1000;/*w ww  .j  ava 2  s .co m*/
        if (second > 60) {
            minute = second / 60;
            second = second % 60;
        }

        if (minute > 60) {
            hour = minute / 60;
            minute = minute % 60;
        }

        String strtime = "";
        if (hour != 0) {
            strtime = hour + ":" + minute + ":" + second;
        } else {
            strtime = minute + ":" + (second >= 10 ? second : "0" + second);
        }
        return strtime;
    }

}

Related Tutorials