public static void main(String[] args) {
// 获取当前日期
LocalDate currentDate = LocalDate.now();
// 计算两个月之前的日期
LocalDate twoMonthsAgo = currentDate.minusMonths(2);
// 获取两个月之前的年份和月份
int year = twoMonthsAgo.getYear();
int month = twoMonthsAgo.getMonth().getValue();
// 如果跨年,则返回-1
if (month > currentDate.getMonthValue()) {
month = -1;
}
// 存储所有月份的列表
List<Month> monthsList = new ArrayList<>();
// 循环获取两个月之前的所有月份
for (int i = 1; i <= month; i++) {
monthsList.add(Month.of(i));
}
// 打印所有月份
for (Month m : monthsList) {
System.out.println(m.getValue());
}
}