public String getTimeDifference(Timestamp endTime, Timestamp startTime) {
SimpleDateFormat timeformat = new SimpleDateFormat("yyyy-MM-dd,HH:mm:ss");
long t1 = endTime.getTime();
long t2 = startTime.getTime();
int hours=(int) ((t1 - t2)/(1000*60*60));
int minutes=(int) (((t1 - t2)/1000-hours*(60*60))/60);
int second=(int) ((t1 - t2)/1000-hours*(60*60)-minutes*60);
return ""+hours+"小时"+minutes+"分"+second+"秒";
}
currentTime:当前时间:系统默认生成的当前时间
startTime:开始任务的时间:从数据库中取出
String useTime = getTimeDifference(currentTime, startTime);
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/8d8f8ea1f6a41a031343dc2c73fdaa53.png)