public LinkedList<String> getMonthBydate(String date) {
Calendar c= Calendar.getInstance();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM");
LinkedList<String> months= new LinkedList<>();
try {
Date parse = sdf.parse(date);
c.setTime(parse);
int year = c.get(Calendar.YEAR);
String s = String.valueOf(year);
String strStartDate=s+"-01";
Date startDate = sdf.parse(strStartDate);
Date endDate = sdf.parse(date);
if(startDate!=null&&endDate!=null){
for(Date indexdateDate=startDate;indexdateDate.compareTo(endDate)<=0;){
String dateString = sdf.format(indexdateDate);
months.add(dateString);
c.setTime(indexdateDate);
c.add(Calendar.MONTH, 1);
indexdateDate=c.getTime();
}
}
} catch (ParseException e) {
e.printStackTrace();
}
return months;
}
根据传的yyyy-mm 获取当前月份以及之前月份的list
最新推荐文章于 2023-06-09 19:35:08 发布