Here you can find the source of format(long ms)
Parameter | Description |
---|---|
ms | milliseconds |
public static String format(long ms)
//package com.java2s; public class Main { /**//w w w .j ava 2 s.co m * Transform the time in milliseconds to the time in "dd hh:mm:ss.SSS" * format. * * @param ms milliseconds * @return dd hh:mm:ss.SSS */ public static String format(long ms) { int ss = 1000; int mi = ss * 60; int hh = mi * 60; int dd = hh * 24; long day = ms / dd; long hour = (ms - day * dd) / hh; long minute = (ms - day * dd - hour * hh) / mi; long second = (ms - day * dd - hour * hh - minute * mi) / ss; long milliSecond = ms - day * dd - hour * hh - minute * mi - second * ss; String strDay = day < 10 ? "0" + day : "" + day; String strHour = hour < 10 ? "0" + hour : "" + hour; String strMinute = minute < 10 ? "0" + minute : "" + minute; String strSecond = second < 10 ? "0" + second : "" + second; String strMilliSecond = milliSecond < 10 ? "0" + milliSecond : "" + milliSecond; strMilliSecond = milliSecond < 100 ? "0" + strMilliSecond : "" + strMilliSecond; return new StringBuffer(strDay).append(" ").append(strHour).append(":").append(strMinute).append(":") .append(strSecond).append(".").append(strMilliSecond).toString(); } }