public static String getTimeDiffText2(Timestamp processTime, Timestamp planTime) {
String titleText;
Timestamp now = Time.now().toTimestamp();
//未超时处理
if (processTime != null && processTime.before(planTime)) {
return null;
} else if (processTime != null && processTime.after(planTime)) {
titleText = "超时";
} else if (processTime == null && now.before(planTime)) {
titleText = "剩余";
} else if (processTime == null && now.after(planTime)) {
titleText = "超时";
} else {
return null;
}
processTime = processTime == null ? now : processTime;
int seconds;
int minutes;
int hour;
int day;
int year;
int minuteSeconds = 60;
int hourSeconds = 60 * minuteSeconds;
int daySeconds = 24 * hourSeconds;
double totalSeconds = Time.when(processTime).between(Time.when(planTime.getTime())).toSeconds();
day = (int) (totalSeconds / daySeconds);
if (day > 0) {
totalSeconds -= day * daySeconds;
}
hour = (int) (totalSeconds / hourSeconds);
if (hour > 0) {
totalSeconds -= hour * hourSeconds;
}
minutes = (int) (totalSeconds / minuteSeconds);
if (minutes > 0) {
totalSeconds -= minutes * minuteSeconds;
}
seconds = (int) totalSeconds;
return titleText + day + "天" + hour + "小时" + minutes + "分钟" + seconds + "秒";
}
public static void main(String[] args) { System.out.println(getTimeDiffText(null, new Timestamp(1666056045000L))); }
标签:相差,planTime,int,processTime,分钟,totalSeconds,null,多少,titleText From: https://www.cnblogs.com/LQBlog/p/16801801.html