patternin MM/yy的DateTimeFormatter

Ale*_*eux 1 java java-8

我这样做时遇到了这个错误

LocalDate.parse(expirationDate,DateTimeFormatter.ofPattern("MM/yy");

java.time.format.DateTimeParseException: Text '09/14' could not be parsed at index 5
Run Code Online (Sandbox Code Playgroud)

我和建筑师一起测试但是我不知道怎么做?

有人有一些线索吗?

谢谢!

Psh*_*emo 7

LocalDate需要包含一天.如果您不打算提供它,则可以使用YearMonth.

YearMonth yearMonth = YearMonth.parse("09/14",DateTimeFormatter.ofPattern("MM/yy"));
Run Code Online (Sandbox Code Playgroud)

您可以稍后使用某些日期值构建LocalDate

LocalDate firstDay = yearMonth.atDay(1);
Run Code Online (Sandbox Code Playgroud)