Here you can find the source of formatDuration(long millis)
public static String formatDuration(long millis)
//package com.java2s; //License from project: Apache License public class Main { /**/* w w w. jav a 2 s . c o m*/ * Returns specified duration as a string in the following format: * "hours:minutes:seconds.milliseconds". */ public static String formatDuration(long millis) { final int millisInSecond = 1000; final int millisInMinute = 60 * 1000; final int millisInHour = 60 * 60 * 1000; int hours = (int) (millis / millisInHour); millis = millis - (hours * millisInHour); int minutes = (int) (millis / millisInMinute); millis = millis - (minutes * millisInMinute); int seconds = (int) (millis / millisInSecond); millis = millis - (seconds * millisInSecond); int milliseconds = (int) millis; StringBuilder result = new StringBuilder(16); result.append(hours); result.append(':'); result.append((char) (minutes / 10 + '0')); result.append((char) (minutes % 10 + '0')); result.append(':'); result.append((char) (seconds / 10 + '0')); result.append((char) (seconds % 10 + '0')); result.append('.'); if (milliseconds < 10) { result.append('0').append('0'); } else if (milliseconds < 100) { result.append('0'); } result.append(milliseconds); return result.toString(); } }