Here you can find the source of formatDuration(long milliseconds)
public static String formatDuration(long milliseconds)
//package com.java2s; //License from project: Apache License public class Main { public static String formatDuration(long milliseconds) { int s = (int) (milliseconds / 1000); milliseconds = milliseconds % 1000; int m = s / 60; s = s % 60;/*from w w w . j a va 2 s. c o m*/ int h = m / 60; m = m % 60; return padWithLeadingZeros(h, 2) + ":" + padWithLeadingZeros(m, 2) + ":" + padWithLeadingZeros(s, 2) + "." + padWithLeadingZeros((int) milliseconds, 3); } public static String padWithLeadingZeros(int n, int minLength) { return padWithLeadingZeros("" + n, minLength); } public static String padWithLeadingZeros(String s, int minLength) { while (s.length() < minLength) s = "0" + s; return s; } }