Here you can find the source of toTimeString(long milliseconds)
public static String toTimeString(long milliseconds)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { public static String toTimeString(Date value) { if (value != null) { SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); return dateFormat.format(value); } else {/* ww w .ja v a2 s .c om*/ return ""; } } public static String toTimeString(long milliseconds) { long secs = milliseconds / 1000; long mins = secs / 60; long hours = mins / 60; secs = secs % 60; mins = mins % 60; if (hours > 0) { return String.format("%d:%02d:%02d", hours, mins, secs); } return String.format("%d:%02d", mins, secs); } }