Calendar from = Calendar.getInstance();
from.setTime(DateUtil.currentDate());//当前月
String endStr = from.get(Calendar.YEAR)+"-"+(from.get(Calendar.MONTH)+1)+"-"+from.get(Calendar.DATE);
from.add(Calendar.MONTH, -11);//11个月前
String startStr = from.get(Calendar.YEAR)+"-"+(from.get(Calendar.MONTH)+1)+"-"+from.get(Calendar.DATE);
Date endDate = DateUtil.string2Date(endStr);
Date startDate = DateUtil.string2Date(startStr);
DateUtil.string2Date:这个方法的意思 是String转Date类型。可用相应代码替代,例如:
String dateString = "2021-07-01";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate date = LocalDate.parse(dateString, formatter);