public class TestTotal {
public static void main(String[] args) throws ParseException {
for (int j = 0; j < 3; j++) {
Map<String, Date> map = getMonthDate("2021-02-01", j);
System.out.println(map.get("开始月份")+"-------"+map.get("结束月份"));
}
}
private static Map<String, Date> getMonthDate(String startDateStr, int j) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date startDate = sdf.parse(startDateStr);
Map<String, Date> dateMap = new HashMap<>();
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
calendar.set(calendar.MONTH,calendar.get(Calendar.MONTH)+j);
dateMap.put("开始月份",calendar.getTime());
int lastDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
calendar.set(Calenda
Java根据当月第一天获取多个月的第一天(开始日期)跟最后一天(结束日期)----calendar获取月份
最新推荐文章于 2024-06-30 03:12:10 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)