如果小于等于24小时为true;大于24小时为false。参数是更新时间
public boolean isIn24H(Date updateTime){
Date date = new Date();
String updateTime1 = updateTime.toString().substring(0,19);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date end = null;
try {
String format = sdf.format(date);
end = sdf.parse(format);
java.util.Date start = sdf.parse(updateTime1);
long cha = end.getTime() - start.getTime();
double result = cha * 1.0 / (1000 * 60 * 60);
if(result<=24){
return true;
}else {
return false;
}
} catch (ParseException e) {
e.printStackTrace();
}
return false;
}
参数是一个List集合(与上面的方法一块使用)
public Boolean onLine(List<MonitorDevice> findDrainage){
List<MonitorDevice> collect = findDrainage.stream().filter(s -> isIn24H(s.getUpdateTime())).collect(Collectors.toList());
if (collect.size()>0){
return true;
}else {
return false;
}
}
标签:24,判断,false,end,return,sdf,Date,小时 From: https://www.cnblogs.com/sensenh/p/16824687.html