获取最近6个月的年月(yyyyMM,不包括当月)

 1 public static List<String> get6Month() {
 2         
 3         List<String> list = new ArrayList<>();
 4         
 5         SimpleDateFormat sdf=new SimpleDateFormat("yyyyMM");
 6         for (int i = 6; i > 0; i--) {
 7             
 8             Calendar calendar = Calendar.getInstance();
 9             //获取当前时间的前6个月
10             calendar.add(Calendar.MONTH,-i);
11             //将calendar装换为Date类型
12             Date date = calendar.getTime();
13             
14             System.out.println(sdf.format(date));
15             list.add(sdf.format(date));
16             
17         }
18         
19         return list;
20     }
原文地址:https://www.cnblogs.com/clear5/p/6825734.html