我正在尝试解析这个字符串 2020-05-20 14:27:00.943000000 +00:00
和这个 Wed May 20 14:27:00 CEST 2020
到一个 ISO_INSTANT,但总是返回这个异常。
java.time.format.DateTimeParseException: Text '2020-05-20 14:27:00.943000000 +00:00' could not be parsed at index 10
我的代码是:
protected Instant parseDateTime(String fechaHora) {
DateTimeFormatter formatter = DateTimeFormatter.ISO_INSTANT;
TemporalAccessor temporalAccessor = formatter.parse(fechaHora);
LocalDateTime localDateTime = LocalDateTime.from(temporalAccessor);
ZonedDateTime zonedDateTime = ZonedDateTime.of(localDateTime, ZoneId.systemDefault());
Instant result = Instant.from(zonedDateTime);
return result; }
我该如何转换这些类型?
DateTimeFormatter
,或者使用DateTimeFormatterBuilder
。这些类已经被覆盖了很多次,搜索以获取更多信息。从这里开始。 - undefinedString
,也不是文本。像OffsetDateTime
这样的日期-时间对象没有“格式”。 - undefined