JodaTime - how can I know whether a daylight saving occurs within a specified period of time?

╄→尐↘猪︶ㄣ 提交于 2019-12-01 06:14:17

Use the DateTimeZone.nextTransition method. If the start is less than the end DateTime, then at least one time zone transition has occurred in between. This does not account for rule changes vs. DST. That is, a time zone might have a new rule indicating that standard time has a new offset, and this would appear as a time zone transition.

if (start.getZone().nextTransition(start.getMillis()) < end.getMillis()) {
    // Time zone transition occurred, possibly due to DST
    ...
}

As long as start and end are in the correct time zone (e.g., created using this constructor) then the Interval created using them should take DST for that time zone into account. If the Duration of that Interval is not equal to 24 hours, then you've crossed the DST point.

Because Daylight Savings Time is heavily reliant on TimeZones (some areas don't practice DST, some move clocks 1 hour, some 2 etc) your time variables are going to have to account for location as well.

As such, you might have to have a look at the DateTimeZone class

DateTimeZone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!