我已将这个时间范围存储在数据库中:伦敦(英国夏令时)从 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 之前