java - 无法将 2020 年 4 月 15 日上午 12:14:17 的日期解析为 LocalDatetime
问题描述
我正在尝试使用将 2020 年 4 月 15 日 12:14:17 AM 解析为 LocalDateTime
DateTimeFormatter.ofPattern("MMM DD',' YYYY h:mm:ss a")
我得到了例外
Exception in thread "main" java.time.format.DateTimeParseException: Text 'Apr 15, 2020 12:14:17 AM' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {MonthOfYear=4, WeekBasedYear[WeekFields[SUNDAY,1]]=2020, DayOfYear=15},ISO resolved to 00:14:17 of type java.time.format.Parsed
at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1920)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1855)
at java.time.LocalDateTime.parse(LocalDateTime.java:492)
at com.paypal.Test.main(Test.java:76)
解决方案
试试这种日期和年份小写的格式。
DateTimeFormatter.ofPattern("MMM dd',' yyyy hh:mm:ss a")
推荐阅读
- r - 在 RMarkdown 中的代码旁边添加按钮以隐藏/显示代码
- c++ - std::memcpy 是否使其目的地确定?
- css - 转换后继续文档流: translateY(-50%)
- export - 如何更改导出的 SSRS 报告的文件名
- java - 如何在 Java FXML 应用程序中初始化 DatePicker?
- java - 如何从一个方法中给出 2 种不同的数据类型
- kdb - .Q.hg 需要什么版本的 openssl?
- networking - 如何使用 gcloud 将静态 IP 附加到虚拟机?
- python - Flask 形式的动态长度表
- typescript - 具有相等运算符的打字稿泛型类型是什么意思?