Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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"
like image 862
Nir Avatar asked Mar 11 '16 22:03

Nir


1 Answers

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

like image 146
Ali Seyedi Avatar answered Oct 18 '22 17:10

Ali Seyedi