What is Java BST ZoneId?

I store this time interval in the database: any day from 15:00 to 16:00 in LONDON (BST)

I need to execute an IF program when I receive an event between this time frame.

Now I run the test in Paris (16:22), where in London 15:22 (so between the time frame stored in the database).

SO this is my code

// 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())); 

theoretically now (16:22 in PARIS / 15:22 in LONDON) after dateTime1 in LONDON (15:00) and before dateTime2 (16:00) in LONDON

but I realized that now is not up to this dateTime2

+5
source share
1 answer

As stated in javadoc ZonedId.SHORT_IDS , "BST" is not British Daylight Saving Time, but Bangladesh Standard Time ( Asia/Dhaka ).

You can check the value with:

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

Therefore, I suggest using the names of full time zones to avoid confusion:

 ZoneId london = ZoneId.of("Europe/London") 
+9
source

Source: https://habr.com/ru/post/1268873/


All Articles