public static List<String> getIntermediateMonth(String startDate, String endDate) {
List<String> days = new ArrayList<String>();
Calendar startTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
try {
//将开始日期设置给calendar
startTime.setTime(sdf.parse(startDate));
System.out.println("开始日期=" + sdf.format(startTime.getTime()));
startTime.add(Calendar.MONTH, -1);//月份减1,包含开始日期月份
//将结束日期设置给calendar
endTime.setTime(sdf.parse(endDate));
System.out.println("结束日期=" + sdf.format(endTime.getTime()));
while (startTime.before(endTime)) {
startTime.add(Calendar.MONTH, 1);
days.add(sdf.format(startTime.getTime()));
}
System.out.println("days=" + days.toString());
} catch (Exception e) {
e.printStackTrace();
}
return days;
}
获取时间段内的月份
最新推荐文章于 2024-01-18 00:45:00 发布