例子:即:当前时间为8月,时间轴展示从上一年9月开始到当月(包含当月)的每个月的数据
获取当前月格式:2021-09 以及获取
向前12个月怎么获取?
时间轴展示有没有具体的格式?
Date dt = new Date();
Calendar c = Calendar.getInstance();
c.setTime(dt);
List<String> yearMonthList = new ArrayList<>();
for(int i = 0; i < 12; i ++) {
int month = c.get(Calendar.MONTH) + 1;
int year = c.get(Calendar.YEAR);
yearMonthList.add(year + "-" + month);
c.add(Calendar.MONTH, -1);
}
for(String result:yearMonthList) {
System.out.println(result);
}