List of utility methods to do Millisecond Convert
String | millisecondsToDateTime(long timeMillis) milliseconds To Date Time long day = timeMillis / (24 * 60 * 60 * 1000); long hour = (timeMillis / (60 * 60 * 1000) - day * 24); long min = ((timeMillis / (60 * 1000)) - day * 24 * 60 - hour * 60); long s = (timeMillis / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60); long sss = (timeMillis - day * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000 - s * 1000); return (day > 0 ? day + "," : "") + hour + ":" + min + ":" + s + "." + sss; |
int | millisecondsToDays(long p_timeInMilliseconds, long p_secondsInDay) milliseconds To Days int seconds = (new Long(p_timeInMilliseconds / MILLIS_PER_SECOND)).intValue(); int days = 0; if (Math.IEEEremainder(seconds, p_secondsInDay) != 0) { days += 1; if (seconds >= p_secondsInDay) { days += seconds / p_secondsInDay; return days; |
String | millisecondsToHHMMSS(long milliseconds) Convert a time in milliseconds to "hh:mm:ss" format. long total = (milliseconds / 1000); long hours = total / 3600; total = total - (hours * 3600); long minutes = total / 60; total = total - (minutes * 60); long seconds = total; String sHours = hours + ""; String sMinutes = minutes + ""; ... |
String | milliSecondsToHMS(long l) milli Seconds To HMS l /= 1000; long secs = l % 60; long hrs = l / 3600; long mins = (l - (hrs * 3600)) / 60; return String.format("%1$02d:%2$02d:%3$02d", hrs, mins, secs); |
String | milliSecondsToHMS(long numMillis) milli Seconds To HMS if (numMillis < 0) { return "-"; DecimalFormat restFormatter = new DecimalFormat("00.00"); int numSeconds = (int) (numMillis / 1000); long rest = numMillis - numSeconds * 1000; int hours = numSeconds / 3600; int minutes = (numSeconds % 3600) / 60; ... |
String | millisecondsToHuman(long ms) Convert from milliseconds to a human readable format with days, hours, minutes, seconds and the remaining milliseconds. StringBuilder sb = new StringBuilder(); boolean includeRemainingMs = true; if (ms >= MS_PER_MINUTE) { includeRemainingMs = false; if (ms >= 0) { if (ms >= MS_PER_DAY) { sb.append(millisecondsToDays(ms)); ... |
String | millisecondsToHumanDateWithSeconds(long milliseconds) milliseconds To Human Date With Seconds SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); sdf.setTimeZone(CURRENT_TIME_ZONE); Date t = new Date(); t.setTime(milliseconds); return sdf.format(t); |
String | millisecondsToHumanTime(long period) milliseconds To Human Time if (period % MILLIS_IN_SECOND >= HALF_MILLIS_IN_SECOND) { period += MILLIS_IN_SECOND; period /= MILLIS_IN_SECOND; long secs = period % SECONDS_IN_MINUTE; period /= SECONDS_IN_MINUTE; long mins = period % MINUTES_IN_HOUR; period /= MINUTES_IN_HOUR; ... |
Long | millisecondsToNanoseconds(Long milliseconds) milliseconds To Nanoseconds return milliseconds != null ? millisecondsToNanoseconds((long) milliseconds) : null; |
String | millisecondsToSeconds(long ms) Convert from milliseconds to seconds. int seconds = (int) (ms / MS_PER_S); return seconds + "s"; |