我在DB中存儲了這個時間幀:倫敦(BST)從15:00到16:00的任何一天Java的BST ZoneId代表什麼?
我需要執行一個程序,當我收到一個事件時,就是在這個時間範圍之間。
我現在在巴黎進行測試(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
**切勿使用時區3-4字符縮寫**那些*不是*實時區域,不是標準化的,甚至不是唯一的!使用[歐洲/倫敦](https://en.m。)格式的[大陸/地區]格式的[真實時區名稱](https://en.m.wikipedia.org/wiki/List_of_tz_database_time_zones) ,「歐洲/巴黎」(https://en.m.wikipedia.org/wiki/Europe/Paris),「亞洲/加爾各答」,「太平洋/奧克蘭」。 –