Java 如何解析具有毫秒和偏移量的时间?
我想将以下时间字符串解析为Java 如何解析具有毫秒和偏移量的时间?,java,java-time,Java,Java Time,我想将以下时间字符串解析为java.time: OffsetDateTime.parse("00:00:00.000+02:00", DateTimeFormatter.ISO_OFFSET_TIME); 结果: java.time.format.DateTimeParseException: Text '00:00:00.000+02:00' could not be parsed: Unable to obtain OffsetDateTime from TemporalAccessor:
java.time
:
OffsetDateTime.parse("00:00:00.000+02:00", DateTimeFormatter.ISO_OFFSET_TIME);
结果:
java.time.format.DateTimeParseException: Text '00:00:00.000+02:00' could not be parsed: Unable to obtain OffsetDateTime from TemporalAccessor: {OffsetSeconds=7200},ISO resolved to 00:00 of type java.time.format.Parsed
at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1918)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1853)
at java.time.OffsetDateTime.parse(OffsetDateTime.java:402)
那么,如果不是这样的话,这次我怎么能解析呢?An表示
带有偏移量的日期时间的不可变表示形式此类存储所有日期和时间字段,精度为纳秒,以及UTC/格林威治的偏移量
但是您试图解析一个没有日期部分的日期字符串
"00:00:00.000+02:00"
解析无法从中提取日期,因此失败
你似乎想使用
此类存储所有时间字段,精度为纳秒,如下所示:
以及区域偏移
如果您有
LocalDate
,则可以将其转换为OffsetTime\atDate
您正在分析日期时间,日期在哪里?提示:使用OffsetTime
.Doh。。。你能补充一下吗。虽然这应该是显而易见的,但对我来说显然不是。