首页 > 其他分享 >计算2个时间相差多少天多少分钟多少秒

计算2个时间相差多少天多少分钟多少秒

时间:2022-10-18 10:46:27浏览次数:50  
标签:相差 planTime int processTime 分钟 totalSeconds null 多少 titleText

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

相关文章