Caused by: java.time.DateTimeException: Conflict found: Field DayOfWeek 6 differs from DayOfWeek 2 derived from 2016-01-30

只谈情不闲聊 提交于 2021-02-08 19:46:37

问题


I am parsing dates like this: "Sat, 30 Jan 2016 00:03:00 +0300"

But in some of the dates it throw me this exception:

Caused by: java.time.DateTimeException: Conflict found: Field DayOfWeek 6 differs from DayOfWeek 2 derived from 2016-01-30

or this:

java.time.format.DateTimeParseException: Text 'Tue, 30 Jan 2016 00:06:00 +0300' could not be parsed: Conflict found: Field DayOfWeek 6 differs from DayOfWeek 2 derived from 2016-01-30

Here is some of my code:

DateTimeFormatter newformatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);

OffsetDateTime odt = OffsetDateTime.parse( date , newformatter );
Instant instant = odt.toInstant();
java.sql.Timestamp ts = java.sql.Timestamp.from( instant );

Input for example that throws exception:

Input:"Tue, 30 Jan 2016 00:06:00 +0300"
exception: "Text 'Tue, 30 Jan 2016 00:06:00 +0300' could not be parsed: Conflict found: Field DayOfWeek 6 differs from DayOfWeek 2 derived from 2016-01-30"

回答1:


It is simply because 30 Jan 2016 is Saturday and not Tuesday.



来源:https://stackoverflow.com/questions/35950728/caused-by-java-time-datetimeexception-conflict-found-field-dayofweek-6-differ

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!