Konnte nicht analysiert werden: OffsetDateTime konnte nicht von TemporalAccessor abgerufen werden

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Konnte nicht analysiert werden: OffsetDateTime konnte nicht von TemporalAccessor abgerufen werden

by Guest » 11 Jan 2025, 08:48

Ich habe diesen Java-Code:

Code: Select all

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();
Ich habe versucht, es auf diese Weise zu migrieren:

Code: Select all

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());
Ich erhalte die Fehlermeldung:

Code: Select all

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
Wenn ich DATE_TIME_FORMATTER entferne, funktioniert der Code wie folgt:

Code: Select all

OffsetDateTime txnTime = OffsetDateTime.from(
OffsetDateTime.parse(transactionTime).toInstant()
Wissen Sie, wie ich das beheben kann?

Top