admin管理员组

文章数量:1123046

I have this java code:

import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import java.util.Date;

DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");

String transactionTime = "2019-02-26T13:43:12Z";
Date txnTime = DATE_TIME_FORMATTER.parseDateTime(transactionTime).toDate();

I tried to migrate it this way:

import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");

String transactionTime = "2019-02-26T13:43:12Z";
OffsetDateTime txnTime = OffsetDateTime.from(OffsetDateTime.parse(transactionTime, DATE_TIME_FORMATTER).toInstant());

I get error:

Text '2019-02-26T13:43:12Z' could not be parsed: Unable to obtain OffsetDateTime from TemporalAccessor: {},ISO resolved to 2019-02-26T13:43:12 of type java.time.format.Parsed 

When I remove DATE_TIME_FORMATTER the code is working fine like this: OffsetDateTime txnTime = OffsetDateTime.from(OffsetDateTime.parse(transactionTime).toInstant()

Do you know how I can fix this?

本文标签: javacould not be parsed Unable to obtain OffsetDateTime from TemporalAccessorStack Overflow