public static void main(String[] args) {
// 指定年份和月份
int year = 2023; int month = 6;
// 创建 LocalDate 对象表示指定年份和月份的第一天
LocalDate date = LocalDate.of(year, month, 1);
// 获取该月的总天数 int daysInMonth = date.lengthOfMonth();
System.out.println("该月的总天数:" + daysInMonth);
// 遍历每一天,并获取对应的星期几和日期
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEEE");
for (int day = 1; day <= daysInMonth; day++) {
String dayOfWeek = date.format(formatter);
System.out.println("第 " + day + " 天是:" + dayOfWeek + ", 日期:" + date);
// 切换到下一天 date = date.plusDays(1);
} }