为了比较系统时间和服务器数据库存储的时间(用的是Timestamp类型存储的)
Timestamp类型呦befor和after方法能够比较时间的大小
简单的测试
Timestamp b = Timestamp.valueOf("2019-09-24 20:39:00");
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
Timestamp c = Timestamp.valueOf(f.format(date));
System.out.println(c);
if (!(b.before(c)) && !(b.after(c))) {
System.out.println("b==c");
return;
} else {
System.out.println("b!=c");
}
可以用SimpleDateFormat规定格式,在转换为Timestamp类型即可去除秒后面接的数字
最后实现
Equipment_messageS equipment_messageS = hAndMMapper.findOne(hAndM);
Timestamp mysqlTime = equipment_messageS.getTime1(); //数据库存储时间
//处理时间格式
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
Timestamp LocalTime = Timestamp.valueOf(f.format(date)); //本地时间
if (!(mysqlTime.before(LocalTime))&&!(mysqlTime.after(LocalTime))){
省略......
}