How to show the difference in time after the daylight saving started in Java?

前端 未结 2 934
旧时难觅i
旧时难觅i 2020-12-20 07:22

I wanted to check the difference in time before and after the daylight saving time started. I am using a JVM where timezone has some issue with DST WRT Brazilian time. I cou

2条回答
  •  情歌与酒
    2020-12-20 07:25

    I'll add a very brief answer. It shows that 1 day is not equal to 24 hours, i.e. DST changed. I also stepped over to Java 8 because I'm more familiar with it.

    ZoneId timezone = ZoneId.of("Brazil/East");
    
    ZonedDateTime t = ZonedDateTime.of(2018, 10, 20, 7, 52, 16, 0, timezone);
    
    System.out.println(t);
    System.out.println(t.plus(1, ChronoUnit.DAYS));
    System.out.println(t.plus(24, ChronoUnit.HOURS));
    

    Output:

    2018-10-20T07:52:16-03:00[Brazil/East]
    2018-10-21T07:52:16-02:00[Brazil/East]
    2018-10-21T08:52:16-02:00[Brazil/East]

提交回复
热议问题