private static void changeDateListToTreeMap(List<Date> dateList, Map<String, Object> map) {
for (Date date : dateList) {
LocalDate temp = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
int year = temp.getYear();
int month = temp.getMonthValue();
int day = temp.getDayOfMonth();
Map<String, Object> monthMap = (Map<String, Object>) map.get(year + "");
if (CollectionUtils.isEmpty(monthMap)) {
monthMap = new HashMap<String, Object>();
}
List<Integer> dayList = (List<Integer>)monthMap.get(month + "");
if (CollectionUtils.isEmpty(dayList)) {
dayList = new ArrayList<Integer>();
}
dayList.add(day);
monthMap.put(month + "", dayList);
map.put(year + "", monthMap);
}
}
转换后格式:
"data":{"2017":{"3":[16,17,18,23], "5":[16,17,18,23]},"2018":{"12":[6,20,21,22,29]}}