package com.qianwen.smartman.common.utils;
|
|
import java.time.Duration;
|
|
public class DurationUtil {
|
/**
|
* 将时间差转换为中文,如1天2小时3分15秒
|
* @param duration
|
* @return 中文时间差
|
*/
|
public static String toChineseDuration(Duration duration) {
|
String dayStr = "";
|
if(duration.toDays() > 0) {
|
dayStr = duration.toDays()+"天";
|
}
|
|
long temp;
|
|
String secStr = "";
|
if(duration.getSeconds() > 0) {
|
temp = duration.getSeconds()%60;
|
if(temp > 0) {
|
secStr = temp+"秒";
|
}
|
}
|
|
String minStr = "";
|
if(duration.toMinutes() > 0) {
|
temp = duration.toMinutes()%60;
|
if(temp > 0) {
|
minStr += temp+"分";
|
}
|
}
|
|
String hourStr = "";
|
if(duration.toHours() > 0) {
|
temp = duration.toHours()%24;
|
if(temp > 0) {
|
hourStr = temp+"小时";
|
}
|
}
|
|
|
|
return dayStr + hourStr+minStr+secStr;
|
}
|
}
|