Bla*_*man 3 java timezone datetime datetime-parsing zoneddatetime
我该如何解析PDT时区中的日期时间值?
06/24/2017 07:00 AM (PDT)
Run Code Online (Sandbox Code Playgroud)
我想维护时区,以便我可以根据网站访问者的偏好来表示其他时区的时间.
我尝试使用,ZonedDateTime但我得到一个解析错误:
java.time.ZonedDateTime.parse("06/24/2017 07:00 AM (PDT)")
Run Code Online (Sandbox Code Playgroud)
错误是:
java.time.format.DateTimeParseException: Text '06/24/2017 07:00 AM (PDT)' could not be parsed at index 0
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
at java.time.ZonedDateTime.parse(ZonedDateTime.java:597)
at java.time.ZonedDateTime.parse(ZonedDateTime.java:582) ... 29 elided
Run Code Online (Sandbox Code Playgroud)
另外,你是否同意我应该使用ZonedDateTime?
由于您的格式是非标准格式,因此您需要将其指定给解析器:
ZonedDateTime.parse(
"06/24/2017 07:00 AM (PDT)",
DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm a (zzz)")
);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
753 次 |
| 最近记录: |