list.stream().sorted((o1, o2) -> {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date dt1 = format.parse(o1.getRecordTime());
Date dt2 = format.parse(o2.getRecordTime());
// 默认降序, 升序的话 把 dt1 和 dt2 调换位置
return Long.compare(dt2.getTime(), dt1.getTime());
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}).collect(Collectors.toList());
stream对对象的日期进行排序
最新推荐文章于 2023-12-19 23:15:25 发布