convert Millis To Minutes And Seconds - Android java.util

Android examples for java.util:Date Time


convert Millis To Minutes And Seconds

Demo Code

import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class Main{

    public static String convertMillisToMinutesAndSeconds(long duration) {
        Date date = new Date(duration);
        DateFormat formatter;// w  w w  .j a v a  2  s  .  c o m
        // if the duration is over an hour add the hour format
        if (duration > 3600000) {
            formatter = new SimpleDateFormat("HH:mm:ss");
            // if over 10 minutes, add the leading digit
        } else if (duration > 600000) {
            formatter = new SimpleDateFormat("mm:ss");
        } else {
            formatter = new SimpleDateFormat("m:ss");
        return formatter.format(date);


Related Tutorials