I want to convert the second/milliseconds in this format \"HH:mm:ss\" (for esamples, from 5 seconds to 00:00:05). I tried to get that format in this way:
int mil
I wrote a simple utility function for this task which does not require any Java version nor instantiates any unnecessary objects:
/**
* provides a String representation of the given time
* @return {@code millis} in hh:mm:ss format
*/
public static final String formatTime(long millis) {
long secs = millis / 1000;
return String.format("%02d:%02d:%02d", secs / 3600, (secs % 3600) / 60, secs % 60);
}
Unlike some other solutions here, this can even deal with up to 100 hours