这很有意义:您输入的内容实际上不是日期,因为它没有日期信息。您应该将其解析为“ a”,
YearMonth并在不关心当天的情况下使用该结果。
String date = "04.2013";DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM.yyyy");YearMonth ym = YearMonth.parse(date, formatter);如果你需要申请一个特定的一天,你可以获得
LocalDate从
YearMonth例如:
LocalDate ld = ym.atDay(1);//orLocalDate ld = ym.atEndOfMonth();
TemporalAdjuster例如,您还可以在月份的最后一天使用*:
LocalDate ld = ym.atDay(1).with(lastDayOfMonth());
*带着
import static java.time.temporal.TemporalAdjusters.lastDayOfMonth;



