NO IMAGE

啥也不多說了,直接貼程式碼,需要的朋友可以拿去直接用,程式碼比較簡單

/*
* 毫秒轉化
*/
public static String formatTime(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 strMinute   " 分鐘 "   strSecond   " 秒";
}

 

下面是一樣的,輸出格式不同而已

    /*
* 毫秒轉化時分秒毫秒
*/
public static String formatTime(Long ms) {
Integer ss = 1000;
Integer mi = ss * 60;
Integer hh = mi * 60;
Integer 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;
StringBuffer sb = new StringBuffer();
if(day > 0) {
sb.append(day "天");
}
if(hour > 0) {
sb.append(hour "小時");
}
if(minute > 0) {
sb.append(minute "分");
}
if(second > 0) {
sb.append(second "秒");
}
if(milliSecond > 0) {
sb.append(milliSecond "毫秒");
}
return sb.toString();
}