Here you can find the source of formatTime(long ms)
public static String formatTime(long ms)
//package com.java2s; public class Main { /** Given elapsed time in milliseconds, return a string formatted HH:MM:SS/*from ww w . ja v a 2 s.co m*/ */ public static String formatTime(long ms) { long h, m, s; s = ms / 1000; // ms -> seconds h = s / 3600; // hours s = s - (h * 3600); m = s / 60; // minutes s = s - (m * 60); s = (s > 0 ? s : 1); // round up to 1 second java.text.NumberFormat time = new java.text.DecimalFormat("00"); return time.format(h) + ":" + time.format(m) + ":" + time.format(s); } }