下面是我的代码片段,它在我的本地失败,但在其他 DEV 的机器上工作,有人能指出我遗漏了什么吗?
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss a z");
ZonedDateTime releaseDate = ZonedDateTime
.parse("2021-03-31 10:15:30 AM +05:30", formatter);
异常
java.time.format.DateTimeParseException: Text '2021-03-31 10:15:30 AM +05:30' could not be parsed at index 20
at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2046)
at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1948)
答案 0 :(得分:0)
我注意到你的模式有两个问题:
您包括 HH
(24 小时制)和 a
(上午/下午)。你可能想要hh
。
您使用 z
(时区 名称),然后显示 +05:30
。也许您想要 Z
或 X
。