其他分享
首页 > 其他分享> > 预估时间毫秒转时分秒毫秒

预估时间毫秒转时分秒毫秒

作者:互联网

DateUtil工具包所用到的
public static final long MILLIS_PER_SECOND = 1000; // Number of milliseconds in a standard second.
public static final long MILLIS_PER_MINUTE = 60 * MILLIS_PER_SECOND; // Number of milliseconds in a standard minute.
public static final long MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE; // Number of milliseconds in a standard hour.
public static final long MILLIS_PER_DAY = 24 * MILLIS_PER_HOUR; // Number of milliseconds in a standard day.
private String remainingSeconds(long time){
StringBuilder stringBuffer = new StringBuilder();
 // 计算天数的值
 long day = time / DateUtil.MILLIS_PER_DAY;
 // 计算小时的值
 long hour = (time - day * DateUtil.MILLIS_PER_DAY) / DateUtil.MILLIS_PER_HOUR;
 // 计算分钟的值
 long minute = (time - day * DateUtil.MILLIS_PER_DAY - hour * DateUtil.MILLIS_PER_HOUR) / DateUtil.MILLIS_PER_MINUTE;
 // 计算秒的值
 long second = (time - day * DateUtil.MILLIS_PER_DAY - hour * DateUtil.MILLIS_PER_HOUR - minute * DateUtil.MILLIS_PER_MINUTE) / DateUtil.MILLIS_PER_SECOND;
 // 计算毫秒的值
 long milliSecond = time - day * DateUtil.MILLIS_PER_DAY - hour * DateUtil.MILLIS_PER_HOUR - minute * DateUtil.MILLIS_PER_MINUTE - second * DateUtil.MILLIS_PER_SECOND;
 if(day > 0) {
stringBuffer.append(day).append("天");
 }
if(hour > 0) {
stringBuffer.append(hour).append("小时");
 }
if(minute > 0) {
stringBuffer.append(minute).append("分");
 }
if(second > 0) {
stringBuffer.append(second).append("秒");
 }
if(milliSecond > 0) {
stringBuffer.append(milliSecond).append("毫秒");
 }
return stringBuffer.toString();
}

标签:DateUtil,long,MILLIS,PER,day,毫秒,append,时分秒,预估
来源: https://blog.csdn.net/Uncnner/article/details/111572870