Java的BST ZoneId代表什么?

我在DB中存储了这个时间框架:伦敦(BST)的15:00到16:00的任何一天

当我在此时间帧之间收到事件时,我需要执行一个程序IF。

我现在在巴黎(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)在伦敦(15:00)的dateTime1之后和伦敦的dateTime2(16:00)之前

但我得到的不是那个dateTime2

正如ZonedId.SHORT_IDS的javadoc ZonedId.SHORT_IDS ,“BST”不是英国夏令时,而是孟加拉国标准时间Asia/Dhaka )。

您可以使用以下方法检查值:

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

所以我建议使用全时区名称以避免混淆:

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