generate Time string in format 00:00:00 from integer - Android java.util

Android examples for java.util:Date Time

Description

generate Time string in format 00:00:00 from integer

Demo Code

import android.text.TextUtils;
import java.util.Arrays;
import java.util.Iterator;

public class Main{

    public static String generateTime(long time) {
        int totalSeconds = (int) (time / 1000);
        int seconds = totalSeconds % 60;
        int minutes = (totalSeconds / 60) % 60;
        int hours = totalSeconds / 3600;

        return hours > 0 ? String.format("%02d:%02d:%02d", hours, minutes,
                seconds) : String.format("%02d:%02d", minutes, seconds);
    }/*from   w  w  w.j a va 2 s .c om*/

}

Related Tutorials