【发布时间】:2018-08-06 23:02:43
【问题描述】:
我正在尝试以特定格式解析当前时间戳,但每次尝试我都会收到java.time.format.DateTimeParseException。我的代码:
ZonedDateTime.parse(
ZonedDateTime.now().toString(),
DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss.SSS")
.withZone(ZoneId.of("UTC")) //I also tried ZoneId.systemDefault()
)
结果:
java.time.format.DateTimeParseException:
Text '2018-02-27T11:01:18.776+01:00[Europe/Berlin]' could not be parsed at index 2
问题是为什么我不能解析成想要的格式以及如何实现呢?
附:我还看到this 的帖子并尝试设置ZoneId,但没有帮助。
【问题讨论】:
-
你的预期输出是什么?
-
呃...那些在formatter参数中指定的。
-
试试
ZonedDateTime.now().format(DateTimeFormatter.ofPattern("...."))
标签: java datetime-format datetime-parsing zoneddatetime