日期时间转换
- 2023-03-30 14:25:00.000
java@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss:sss") private LocalDateTime requestTimeStamp;
- 2021-06-18T10:46:19.673785+08:00
javanew SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss:sssXXX");
- yyyy-mm-dd hh:mm:ss.sss +0530
javayyyy-MM-dd HH:mm:ss.SSS Z
- 24-May-2023
javadd-MMM-yyyy
比较大小
- isAfter()
firstDate.isAfter(secondDate); //date1是否大于date2 大于的话,true;否则false
- isBefore()
firstDate.isBefore(secondDate); //是否小于
- isEqual()
firstDate.isEqual(secondDate);//相等,true;否则false
- LocalDate.now();
获取当前时间
- localDate1.plusDays(5);
localDate1加五天
- localDate2.minusDays(1);
localDate2减一天
用Stream分组
javaMap<String, List<Response>> map =list.stream().collect( Collectors.groupingBy(Response::getId, Collectors.toList()));
用Stream分组后只取日期最新
javaArrayList<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>>
javaMap<LocalDate, List<Response>> result = new LinkedHashMap<>(); map.entrySet().stream().sorted(Collections.reverseOrder(Map.Entry.comparingByKey())).forEachOrdered(x -> result.put(x.getKey(), x.getValue()));
ps:因为如果有内部类 用不了两层 :: 所以只能先转Map
- 按同一订单号分组后,按日期排序
stream筛选
过期的放进list
java
List<Response> overdueList = list.stream().filter(response-> response.getDetails().getDueDate().isBefore(LocalDate.now())).collect(Collectors.toList());