Java的BST ZoneId代表什么?



我已在此时间范围内存储在数据库中:伦敦(BST(从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( 之前

但我明白了,现在不是在那日期之前Time2

ZonedId.SHORT_IDS的javadoc所示,"BST"不是英国夏令时,而是孟加拉国标准时间(Asia/Dhaka(。

您可以使用以下命令检查该值:

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

因此,我建议使用完整的时区名称以避免任何混淆:

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

最新更新