Here you can find the source of toTime(long ms)
Parameter | Description |
---|---|
ms | time in milliseconds |
public static String toTime(long ms)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w .ja va 2 s . co m * Turn the input long into a string on the form (D:)HH:MM:SS, where the * day-part is only added if the number of days is greater than or equal * to 1, i.e. a long value of 86,399,999. * @param ms time in milliseconds * @return string-representation of the input long */ public static String toTime(long ms) { long total = ms / 1000; long secs = total % 60; long mins = total % 3600 / 60; long hours = total / 3600 % 24; long days = total / 3600 / 24; String time = (days > 0 ? days + ":" : "") + (hours < 10 ? "0" + hours : hours) + ":" + (mins < 10 ? "0" + mins : mins) + ":" + (secs < 10 ? "0" + secs : secs); return time; } }