avi*_*iad 4 java datetime date jodatime dst
我需要知道定义的时期是否:
DateTime start;
DateTime end;
Run Code Online (Sandbox Code Playgroud)
里面有一个DST.
我正在迭代{start,end}定义的句点集合,并在每次迭代中向前移动24小时.结果期间从午夜开始,到下午午夜前1毫秒结束.我发现如果周期内有一个夏令时点,那么移位会产生不正确的结果,例如:
有:
Duration targetDuration = new Duration(24*60*60*1000L-1);
DateTime start = new DateTime("2012-03-10T00:00:00.000-08:00");
DateTime end = new DateTime("2012-03-10T23:59:59.999-08:00");
Run Code Online (Sandbox Code Playgroud)
然后转移完成:
start = end.plusMillis(1);
end = start.plus(targetDuration);
Run Code Online (Sandbox Code Playgroud)
生产:
start = "2012-03-11T00:00:00.000-08:00"
end = "2012-03-12T00:59:59.999-07:00"
Run Code Online (Sandbox Code Playgroud)
我想知道JodaTime中是否有任何标准API可以检查一段时间内是否有DST?
使用DateTimeZone.nextTransition方法.如果开始小于结束日期时间,则两者之间至少发生一次时区转换.这不包括与DST相比的规则更改.也就是说,时区可能具有指示标准时间具有新偏移的新规则,并且这将显示为时区转换.
if (start.getZone().nextTransition(start.getMillis()) < end.getMillis()) {
// Time zone transition occurred, possibly due to DST
...
}
Run Code Online (Sandbox Code Playgroud)