Convert long value to HH:MM:SS - Android java.util

Android examples for java.util:Date Time

Description

Convert long value to HH:MM:SS

Demo Code

import android.text.TextUtils;
import java.net.URI;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{


    public static String millisecondToDate(long t) {
        long i = t;
        i /= 1000;/*from   ww w .  j  a v  a  2  s .co  m*/
        long minute = i / 60;
        long hour = minute / 60;
        long second = i % 60;
        minute %= 60;
        if (hour <= 0)
            return String.format(Locale.getDefault(), "%02d:%02d", minute,
                    second);
        else
            return String.format(Locale.getDefault(), "%02d:%02d:%02d",
                    hour, minute, second);
    }

}

Related Tutorials