尝试从日期字符串解析 ZonedDateTime,例如“2020-08-24”。
在使用 TemporalAccesor 和 DateTimeFormatter.ISO_OFFSET_DATE 进行解析时,我得到一个 java.time.format.DateTimeParseException。我使用了错误的格式化程序吗?
甚至尝试在日期字符串的末尾添加“Z”以将其理解为 UTC
private ZonedDateTime getZonedDateTime(String dateString) {
TemporalAccessor parsed = null;
dateString = dateString + 'Z';
try {
parsed = DateTimeFormatter.ISO_OFFSET_DATE.parse(dateString);
} catch (Exception e) {
log.error("Unable to parse date {} using formatter DateTimeFormatter.ISO_INSTANT", dateString);
}
return ZonedDateTime.from(parsed);
}