gpt4 book ai didi

java ZonedDateTime 解析毫秒部分错误

转载 作者:行者123 更新时间:2023-11-30 06:42:24 27 4
gpt4 key购买 nike

ZonedDateTime zdt3 = ZonedDateTime.parse("1999-09-09 09:09:09.999", 
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.xxx"));

运行时错误:

Exception in thread "main" java.time.format.DateTimeParseException: Text '1999-09-09 09:09:09.999' could not be parsed at index 20

如何解决我的问题?

最佳答案

参见 doc ZonedDateTime:

A date-time with a time-zone in the ISO-8601 calendar system, such as 2007-12-03T10:15:30+01:00 Europe/Paris.

1999-09-09 09:09:09.999 不包含任何区域信息,它可能是 LocalDateTime :

LocalDateTime zdt3 = LocalDateTime.parse("1999-09-09 09:09:09.999",
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"));

关于java ZonedDateTime 解析毫秒部分错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53465340/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com