public static void main(String[] args) {
// 按照传入的格式生成一个simpledateformate对象
long diff = 0;
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
// 获得两个时间的毫秒时间差异
try {
Date now = new Date();
Date start = sd.parse("2022-03-24 01:20:25");
diff = now.getTime() - start.getTime();
if (diff > nd) {
System.out.println("超过24小时");
} else {
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String time = sd.format(new Date());
System.out.println(time);
}