5
votes

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
We need the input. The input is important since your dates may not be entirely correct concerning the day of the week.Yassin Hajaj
I edited and add my input and the exception for this inputNir

1 Answers

11
votes

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