Here you can find the source of formatTimeWithMillis(double time)
public static String formatTimeWithMillis(double time)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { public static String formatTimeWithMillis(double time) { int hours = (int) time / 3600; int minutes = (int) (time - (hours * 3600)) / 60; int seconds = (int) time - (hours * 3600) - (minutes * 60); double millis = time - (hours * 3600) - (minutes * 60) - seconds; String hoursString = hours + ""; String minutesString = minutes + ""; String secondsString = seconds + ""; String millisString = new DecimalFormat(".000").format(millis); millisString = millisString.substring(1); while (minutesString.length() < 2) { minutesString = "0" + minutesString; }/* w w w . jav a 2 s . co m*/ while (secondsString.length() < 2) { secondsString = "0" + secondsString; } return (hours == 0 ? "" : hoursString + ":") + minutesString + ":" + secondsString + "." + millisString; } }