SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String format = "2021-04-11 10:20:00";
String snaptime = "2021-04-11 7:12:00";
try {
long l = sdf.parse(format).getTime() - sdf.parse(snaptime).getTime();
/*long day = l / (24 * 60 * 60 * 1000);
long hour = (l / (60 * 60 * 1000) - day * 24);
long min = ((l / (60 * 1000)) - day * 24 * 60 - hour * 60);
long sec = (l/1000-day*24*60*60-hour*60*60-min*60);
System.out.println(day + "天" + hour + "小时" + min + "分" + sec + "秒");*/
//时间差 几个小时
double result = l * 1.0 / (1000 * 60 * 60);
System.out.println(result);
} catch (ParseException e) {
e.printStackTrace();
}