import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
public class testDate {
public static void main(String[] args) {
String month = null;
String dateString;
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM”);
Date date = new Date();
dateString = sdf.format(cal.getTime());
List<String> rqList = new ArrayList<>();
System.out.println(“倒序前\n”);
for (int i = 0; i < 6; i++) {
dateString = sdf.format(cal.getTime());
System.out.println(“dateString”+dateString);
rqList.add(dateString.substring(0, 7));
//xfzeList.add(xfze);
cal.add(Calendar.MONTH, -1);
}
// 倒序
Collections.reverse(rqList);
System.out.println(“倒序后\n”);
for(int i=0;i<rqList.size();i++){
System.out.println(“倒序后日期:”+rqList.get(i));
}
}
}
///输出结果如下:/
倒序前
dateString2017-06
dateString2017-05
dateString2017-04
dateString2017-03
dateString2017-02
dateString2017-01
倒序后
倒序后日期:2017-01
倒序后日期:2017-02
倒序后日期:2017-03
倒序后日期:2017-04
倒序后日期:2017-05
倒序后日期:2017-06