Jodatime IllegalInstantException(Jodatime IlLegalInstantException)
本文介绍了Jodatime IlLegalInstantException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我几乎已经尝试了有关此代码段的所有内容,但仍然出现IlLegalInstentException。
public int getDateDay() {
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
DateTime dt;
try {
dt = formatter.parseDateTime(date);
} catch (IllegalInstantException e) {
dt = formatter.parseLocalDateTime(date).toDateTime();
}
return dt.getDayOfMonth();
}
致命异常:org.joda.time.IllegalInstantException非法即时 由于时区偏移量转换(夏令时"间隙"): 2018年10月21日00:00:00.000(美国/圣保罗)键盘箭头向上 Arrow_Right org.joda.time.chrono.ZonedChronology.localToUTC (ZonedChronology.java:157) Org.joda.time.chrono.ZonedChronology.getDateTimeMillis (ZonedChronology.Java:122) Org.joda.time.chrono.AssembledChronology.getDateTimeMillis (Assembly Chronology.Java:133)org.joda.time.base.BaseDateTime。 (BaseDateTime.java:257)org.joda.time.DateTime。(DateTime.java:532) Org.joda.time.LocalDateTime.toDateTime(LocalDateTime.java:750) Org.joda.time.LocalDateTime.toDateTime(LocalDateTime.java:731)
推荐答案
似乎输入的日期无效。此page中已讨论了该问题。
原因:
Joda-Time只允许键类存储有效的日期时间。为 例如,2月31日不是有效日期,因此无法存储 (部分除外)。
同样的有效日期-时间原则也适用于夏令时 时间(DST)。在许多地方使用DST,在那里本地时钟移动 春天向前走一小时,秋天向后走一小时。这 意味着在春天,有一个当地时间不存在的"缺口" 存在。 错误"因时区偏移转换而导致的即时非法"是指 到了这个缺口。这意味着您的应用程序试图创建 差距内的Date-Time-不存在的时间。自Joda-Time以来 对象必须有效,这是不允许的。
可能的解决方案如下:
使用LocalDateTime,因为所有本地日期时间都有效。
将LocalDate转换为DateTime时,请使用toDateTimeAsStartOfDay(),因为这会处理和管理任何间隔。
/li>分析时,如果要分析的字符串没有时区,请使用parseLocalDateTime()。
这篇关于Jodatime IlLegalInstantException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Jodatime IlLegalInstantException


猜你喜欢
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 获取数字的最后一位 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 转换 ldap 日期 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01