Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date time day light saving issue in java 8 for time zone Australia/Melbourne

I am getting different results for day light saving start and end.

ZoneId zone = ZoneId.of("Australia/Melbourne");
System.out.println(ZonedDateTime.of(2019, 04, 07, 3, 0, 0, 0, zone)); // statement-1
System.out.println(ZonedDateTime.of(2019, 10, 06, 2, 0, 0, 0, zone)); // statement-2

For the first half of day light saving for the year 2019, I am getting result as (2019-04-07T03:00**+10:00**[Australia/Melbourne]). Java is reducing 1 hour to offset value. But for second half of day light saving (statement-2=> 2019-10-06T03:00+11:00[Australia/Melbourne]) , java is adding 1 hour to time and +1 to offset value.

As per my understanding java should increase 1 hour to time and +1 to offset value (end of DST) and while start of DST then java should decrease 1 hour from time and 1 from offset value.

Please help me to get clarification regarding the differences. Is it java 8 issue or my understanding is incorrect ?

like image 737
Ajitdas Avatar asked Oct 25 '25 05:10

Ajitdas


1 Answers

Looking at DST transitions for Australia/Melbourne, the clock was never 02:00 on 2019-10-06 because of the DST change. This is how DST works: after 01:59:59.999999 the clock jumps to 03:00:00.000000.

This is documented in ZonedDateTime.of javadoc:

In the case of a gap, when clocks jump forward, there is no valid offset. Instead, the local date-time is adjusted to be later by the length of the gap. For a typical one hour daylight savings change, the local date-time will be moved one hour later into the offset typically corresponding to "summer".

like image 54
Joni Avatar answered Oct 26 '25 19:10

Joni