patternin MM / yy的DateTimeFormatter

时间:2015-09-27 20:44:57

标签: java java-8

我这样做时出现了这个错误

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

java.time.format.DateTimeParseException: Text '09/14' could not be parsed at index 5

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

有人有一些线索吗?

谢谢!

1 个答案:

答案 0 :(得分:7)

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

YearMonth yearMonth = YearMonth.parse("09/14",DateTimeFormatter.ofPattern("MM/yy"));

您可以稍后使用某些日期值(例如

)构建LocalDate
LocalDate firstDay = yearMonth.atDay(1);