public static void main(String[] args) { int year = 2023; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); while (true) { int weekValue = 1; Calendar calendar = new GregorianCalendar();//***踩坑 // calendar.setFirstDayOfWeek(Calendar.MONDAY); //设置每周的第一天为星期一 calendar.setMinimalDaysInFirstWeek(7); //***设置每周最少为7天 while (true) { calendar.setWeekDate(year, weekValue, 1); String endDate = simpleDateFormat.format(calendar.getTime()); calendar.add(Calendar.DATE, -6); String startDate = simpleDateFormat.format(calendar.getTime()); if (endDate.indexOf(year + "") == -1 && startDate.indexOf(year + "") == -1) { year++; break; } System.out.println("-----" + year + "年第" + weekValue + "周,周一:" + startDate + ",周日:" + endDate); weekValue++; } if (year == 2030) { break; } } }