Here you can find the source of formatTime(long ms)
public static String formatTime(long ms)
//package com.java2s; import java.util.*; public class Main { public static String formatTime(long ms) { Date d = new Date(ms); Calendar c = new GregorianCalendar(); c.setTime(d);//from w w w . j a v a2s .c om String hours = String.valueOf(c.get(Calendar.HOUR)); String minutes = String.format("%02d", c.get(Calendar.MINUTE)); String seconds = String.format("%02d", c.get(Calendar.SECOND)); String millis = String.valueOf(c.get(Calendar.MILLISECOND)); String retval = hours + ":" + minutes + ":" + seconds + "." + millis + (c.get(Calendar.AM_PM) == Calendar.AM ? " AM" : " PM"); return retval; } }