毫秒转化天小时分钟秒

毫秒转化为天小时分钟秒

TimeUtil.java

public class TimeUtil {
    public 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;
 
        if (day > 0) {
            return day + "天" + hour + "小时" + minute + "分钟";
        } else if (hour > 0) {
            return hour + "小时" + minute + "分钟";
        } else if (minute > 0) {
            return minute + "分钟";
        } else {
            return 0 + "分钟";
        }
    }
}

你可能感兴趣的:(java,代码,java)