本文介绍了引起原因:java.time.DateTimeException:发现冲突:字段DayOfWeek 6与从2016-01-30派生的DayOfWeek 2不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在解析这样的日期:"2016年1月30日星期六00:03:00 +0300"

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

或者这个:

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

这是我的一些代码:

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:"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"

推荐答案

这仅仅是因为2016年1月30日是星期六而不是星期二.

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

这篇关于引起原因:java.time.DateTimeException:发现冲突:字段DayOfWeek 6与从2016-01-30派生的DayOfWeek 2不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 22:42