/**
* 格式化时间(xx天xx时xx分xx秒)
* @param mills
* @return
*/
public static String formatTime(long ms) {
if (ms == 0) {
return "";
}
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 seconds = (ms - day * dd - hour * hh - minute * mi) / ss;
StringBuilder sb = new StringBuilder();
if (day > 0) {
sb.append(day + "天" + hour + "时" + minute + "分" + seconds + "秒");
} else if (hour > 0) {
sb.append(hour + "时" + minute + "分" + seconds + "秒");
} else if (minute > 0) {
sb.append(minute + "分" + seconds + "秒");
} else if (seconds > 0) {
sb.append(seconds + "秒");
}
return sb.toString();
}
原文:https://www.cnblogs.com/baimj/p/14095647.html