Here you can find the source of toTimeString(Date value)
public static String toTimeString(Date value)
//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 {/*from w w w . j a va 2 s .co m*/ 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); } }