public static void main(String[] args){
List<实体> voList = new ArraysList<>();
voList.stream().sorted(Comparator.comparing(s -> DateUtils.convertStringToDate(s.getDate(), "yyyy-MM-dd").getTime())).collect(Collectors.toList());
}
/**
* 字符串时间转date
*
* @param dateStr the date str
* @param format the format
* @return the date
*/
public static Date convertStringToDate(String dateStr, String format) {
Date date = null;
try {
SimpleDateFormat sdf = new SimpleDateFormat(format);
if (!StringUtils.isBlank(dateStr)) {
date = sdf.parse(dateStr);
}
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
java使用stream对日期排序
于 2022-06-16 17:40:05 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)