Jodatime:由于时区偏移转换导致的非法瞬间(夏令时 'gap')
Jodatime: Illegal instant due to time zone offset transition (daylight savings time 'gap')
这次崩溃发生在 2 天前,我不明白为什么。一切都完美运行了 1 年:
Fatal Exception: org.joda.time.IllegalFieldValueException Value 2 for hourOfDay is not supported: Illegal instant due to time zone offset transition (daylight savings time 'gap'): 2019-03-31T02:09:00.000 (Europe/Paris)
我的代码:
DateTime dtToRefresh = mDateTime != null ? mDateTime : DateTime.now();
dtToRefresh = dtToRefresh.secondOfMinute().setCopy(0);
dtToRefresh = dtToRefresh.millisOfSecond().setCopy(0);
dtToRefresh = dtToRefresh.hourOfDay().setCopy(hourOfDay);
dtToRefresh = dtToRefresh.minuteOfHour().setCopy(minute);
崩溃开始于:
dtToRefresh = dtToRefresh.hourOfDay().setCopy(hourOfDay);
"hourOfDay" 距离日期时间选择器(经典过程)一小时。
你有什么调查方法吗?
非常感谢!
巴黎夏令时从 3 月 31 日开始,因此从那天起您的代码就会崩溃。所以你没有实现你的代码来支持夏令时。
如果您手动计时意味着您需要为该时区实施 DST 时间。如果它占用系统时间就没问题。
解决方案:
捕获异常并尝试增加 1 小时或减少 1 小时。
try
{
DateTime dtToRefresh = mDateTime != null ? mDateTime : DateTime.now();
dtToRefresh = dtToRefresh.secondOfMinute().setCopy(0);
dtToRefresh = dtToRefresh.millisOfSecond().setCopy(0);
dtToRefresh = dtToRefresh.hourOfDay().setCopy(hourOfDay);
dtToRefresh = dtToRefresh.minuteOfHour().setCopy(minute);
}
catch (IllegalArgumentException iae)
{
dttoRefresh.plusHours(1);
}
这次崩溃发生在 2 天前,我不明白为什么。一切都完美运行了 1 年:
Fatal Exception: org.joda.time.IllegalFieldValueException Value 2 for hourOfDay is not supported: Illegal instant due to time zone offset transition (daylight savings time 'gap'): 2019-03-31T02:09:00.000 (Europe/Paris)
我的代码:
DateTime dtToRefresh = mDateTime != null ? mDateTime : DateTime.now();
dtToRefresh = dtToRefresh.secondOfMinute().setCopy(0);
dtToRefresh = dtToRefresh.millisOfSecond().setCopy(0);
dtToRefresh = dtToRefresh.hourOfDay().setCopy(hourOfDay);
dtToRefresh = dtToRefresh.minuteOfHour().setCopy(minute);
崩溃开始于:
dtToRefresh = dtToRefresh.hourOfDay().setCopy(hourOfDay);
"hourOfDay" 距离日期时间选择器(经典过程)一小时。
你有什么调查方法吗?
非常感谢!
巴黎夏令时从 3 月 31 日开始,因此从那天起您的代码就会崩溃。所以你没有实现你的代码来支持夏令时。
如果您手动计时意味着您需要为该时区实施 DST 时间。如果它占用系统时间就没问题。
解决方案:
捕获异常并尝试增加 1 小时或减少 1 小时。
try
{
DateTime dtToRefresh = mDateTime != null ? mDateTime : DateTime.now();
dtToRefresh = dtToRefresh.secondOfMinute().setCopy(0);
dtToRefresh = dtToRefresh.millisOfSecond().setCopy(0);
dtToRefresh = dtToRefresh.hourOfDay().setCopy(hourOfDay);
dtToRefresh = dtToRefresh.minuteOfHour().setCopy(minute);
}
catch (IllegalArgumentException iae)
{
dttoRefresh.plusHours(1);
}