2019 年 11 月 3 日凌晨 2:00,华盛顿特区的时钟“向后移动”至凌晨 1:00。
这意味着本地时间是这样的:
=== Nov 2nd ===:=== Nov 3rd ===========
:
9 10 11 12 1 2
---+---+---+---+---+-*-+
: +-#-+---+---+---+---
: 1 2 3 4 5
所以,如果事故发生在凌晨 1:30,当我记录它时,应该清楚它是发生在第一时间线(那里的 *
)还是第二时间线(#
)。这对于确定责任和其他法律责任非常重要。
当查看java.time.LocalDateTime
时,它似乎不包含时间线。这是故意的还是疏忽?
如果不包含时间线,是否有更好的Java类来存储本地日期/时间?
最佳答案
按照评论中的建议使用 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]
关于java.time.LocalDateTime,多个时间线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60741448/