Do you know why 4. and 6. prints have wrong hours in following code?
LocalDateTime ldtNow = LocalDateTime.now();
LocalDateTime ldtNextMonth = ldtNow.plusMonths(1);
System.out.println("1. " + ldtNow);
System.out.println("2. " + ldtNextMonth);
System.out.println("3. " + ldtNow.atZone(ZoneId.systemDefault()).toInstant().toString());
System.out.println("4. " + ldtNextMonth.atZone(ZoneId.systemDefault()).toInstant().toString());
System.out.println("5. " + ldtNow.atZone(ZoneOffset.systemDefault()).toInstant().toString());
System.out.println("6. " + ldtNextMonth.atZone(ZoneOffset.systemDefault()).toInstant().toString());
This is what it prints:
1. 2022-10-26T16:53:59.691891
2. 2022-11-26T16:53:59.691891
3. 2022-10-26T14:53:59.691891Z
4. 2022-11-26T15:53:59.691891Z //WRONG?
5. 2022-10-26T14:53:59.691891Z
6. 2022-11-26T15:53:59.691891Z //WRONG?
Prints 3. & 4. test it with ZoneId and prints 5. & 6. with ZoneOffset.
The only difference between 3. & 4. (and 5. & 6.) is the usage of LocalDateTime#plusMonths method. What should I do to get right result for zero time (2022-11-26T14:53:59.691891Z)?