LocalDate的用法
日期时间转换
- 2023-03-30 14:25:00.000
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss:sss")
private LocalDateTime requestTimeStamp;
- 2021-06-18T10:46:19.673785+08:00
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss:sssXXX");
yyyy-MM-dd HH:mm:ss.SSS Z
- 24-May-2023
dd-MMM-yyyy
比较大小
-
isAfter()
-
isBefore()
-
isEqual()
-
LocalDate.now();
-
localDate1.plusDays(5);
-
localDate2.minusDays(1);
用Stream分组
Map<String, List<Response>> map =list.stream().collect( Collectors.groupingBy(Response::getId, Collectors.toList()));
用Stream分组后只取日期最新
ArrayList<Response> groupedList = new ArrayList<>(list.stream()
.collect(Collectors.toMap(Response::getId, Function.identity(),
(c1, c2) -> c1.getDetails().getCreateDate().isAfter(c2.getDetails().getCreateDate()) ? c1 : c2))
.values());
用Stream先分组后排序
按日期分组后,按日期倒序排序
Map<LocalDate, List<Response>> result = new LinkedHashMap<>();
map.entrySet().stream().sorted(Collections.reverseOrder(Map.Entry.comparingByKey())).forEachOrdered(x -> result.put(x.getKey(), x.getValue()));
按同一订单号分组后,按日期排序
stream筛选
过期的放进list
List<Response> overdueList = list.stream().filter(response-> response.getDetails().getDueDate().isBefore(LocalDate.now())).collect(Collectors.toList());

浙公网安备 33010602011771号