This method will format the time given in milliseconds to a string in the 00:00 format - Java java.util

Java examples for java.util:Time

Description

This method will format the time given in milliseconds to a string in the 00:00 format

Demo Code


//package com.java2s;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

public class Main {
    /** This method will format the time given in milliseconds to a string in the 00:00 format */
    public static String formatMillisecond(long milliseconds) {
        return String.format(
                Locale.getDefault(),
                "%02d:%02d",
                TimeUnit.MILLISECONDS.toMinutes(milliseconds)
                        - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
                                .toHours(milliseconds)),
                TimeUnit.MILLISECONDS.toSeconds(milliseconds)
                        - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
                                .toMinutes(milliseconds)));
    }/*from   www. j a v  a  2s .  c om*/
}

Related Tutorials