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
版权声明:本文标题:java - could not be parsed: Unable to obtain OffsetDateTime from TemporalAccessor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736545495a1944441.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论