在华盛顿特区,2019年11月3日凌晨2点,时钟被“拨回”至凌晨1点。
这意味着当地时间是这样的:
=== Nov 2nd ===:=== Nov 3rd ===========
:
9 10 11 12 1 2
---+---+---+---+---+-*-+
: +-#-+---+---+---+---
: 1 2 3 4 5因此,如果事故发生在凌晨1:30,当我记录它时,应该清楚它是发生在第一个时间线(那里的* )还是第二个时间线(那里的# )。这对于确定责任和其他法律责任非常重要。
在查看java.time.LocalDateTime时,它似乎没有包含时间线。这是故意的,还是疏忽?
如果没有包含时间线,有没有更好的Java类来存储本地日期/时间?
发布于 2020-03-18 22:48:28
按照评论中的建议使用ZonedDateTime,您可以尝试使用基准时间,并添加一些分钟以查看结果,如下所示:
public static void main(String[] args) {
// let's take a base time of 1:30 in EST (with daylight saving)
ZonedDateTime nov3rd2019OneThirtyAM = ZonedDateTime
.of(2019, 11, 3, 1, 30, 0, 0, ZoneId.of("America/New_York"));
// add 10 minutes 10 times and print the result each time
for (int i = 0; i < 100; i += 10) {
System.out.println(nov3rd2019OneThirtyAM.plusMinutes(i));
}
}输出如下(检查10分钟与1:50相加的部分,其中有2个):
2019-11-03T01:30-04:00[America/New_York]
2019-11-03T01:30-04:00[America/New_York]
2019-11-03T01:40-04:00[America/New_York]
2019-11-03T01:50-04:00[America/New_York]
2019-11-03T01:00-05:00[America/New_York]
2019-11-03T01:10-05:00[America/New_York]
2019-11-03T01:20-05:00[America/New_York]
2019-11-03T01:30-05:00[America/New_York]
2019-11-03T01:40-05:00[America/New_York]
2019-11-03T01:50-05:00[America/New_York]
2019-11-03T02:00-05:00[America/New_York]https://stackoverflow.com/questions/60741448
复制相似问题