Java的BST ZoneId代表什么?

What does Java's BST ZoneId represent?

我将这个时间范围存储在数据库中:从 15:00 到 16:00 的任何一天,在伦敦(英国夏令时)

如果我在这个时间范围内收到一个事件,我需要执行一个程序。

我 运行 现在在巴黎 (16:22) 参加测试,而在伦敦 15:22(所以在数据库中存储的时间范围之间)。

所以这是我的代码

// create Local Date Time from what I have stored in the DB

LocalDateTime dateTime1 = LocalDateTime.of(2017, Month.JUNE, 15, 15, 00);
LocalDateTime dateTime2 = LocalDateTime.of(2017, Month.JUNE, 15, 16, 00);

Instant now = Instant.now();

System.out.println (now.isAfter (dateTime1.atZone(ZoneId.of("BST", ZoneId.SHORT_IDS)).toInstant()));
System.out.println (now.isBefore(dateTime2.atZone(ZoneId.of("BST", ZoneId.SHORT_IDS)).toInstant()));

理论上现在(巴黎的 16:22 / 伦敦的 15:22)在伦敦的 dateTime1 之后 (15:00) 在伦敦的 dateTime2 (16:00) 之前

但我知道现在不早于 dateTime2

the javadoc of ZonedId.SHORT_IDS, “BST” is not British Summer Time but Bangladesh Standard Time (Asia/Dhaka 所示)。

您可以通过以下方式检查值:

System.out.println(ZoneId.of("BST", ZoneId.SHORT_IDS));

所以我建议使用 full time zone names 以避免混淆:

ZoneId london = ZoneId.of("Europe/London")