【发布时间】:2021-08-02 22:41:20
【问题描述】:
我想将字符串“OCTOBER81984”解析为 Java LocalDate。我正在使用以下代码,但不起作用
LocalDate.parse("OCTOBER81984",
new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.appendPattern("MMMMdyyyy")
.toFormatter(Locale.US)
);
例外是
Exception in thread "main" java.time.format.DateTimeParseException: Text 'OCTOBER81984' could not be parsed at index 12
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
at java.time.LocalDate.parse(LocalDate.java:400)
使用的模式是
MMMM --> Full month name
d --> Day of month with 1 or 2 digits
yyyy --> Year
我已阅读the docs 两次,我的模式看起来不错,但实际上不起作用。
我错过了什么?
【问题讨论】:
-
“但真的不起作用” - 这是什么意思?不编译?抛出异常?返回意外结果?