format Time in int value to 00:00:00 - Android java.util

Android examples for java.util:Date Time

Description

format Time in int value to 00:00:00

Demo Code

package zz.itcast.mediaplayer11.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class StringUtils {
    private static final int HOUR = 1000 * 60 * 60;
    private static final int MIN = 1000 * 60;
    private static final int SEC = 1000;

    public static String formatTime(int time) {
        //???/* www.j  a v a  2s  .com*/
        int hour = time / HOUR;
        //??
        int min = time % HOUR / MIN;
        //?
        int sec = time % MIN / SEC;
        if (hour == 0) {
            return String.format("%02d:%02d", min, sec);
        } else {
            return String.format("%02d:%02d:%02d", hour, min, sec);
        }
    }

    public static String getFormaterSystemTime() {
        SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");//hh:12,HH:24
        return format.format(new Date());//System.currentTimeMillis()
    }

}

Related Tutorials