You should avoid providing each field separately if you work with daylight saving time. Instead, convert using epochMillis, as in the following example.
Instant instant = Instant.ofEpochMilli(dt.getMillis()); ZoneId zoneId = ZoneId.of(dt.getZone().getId(), ZoneId.SHORT_IDS); ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, zoneId);
Otherwise, you will lose one hour on the day of the transition. For example, Germany switched from summer time (GMT + 2) to winter time (GMT + 1) 10/29/2017 at 03:00 GMT + 2, which is 02:00 GMT + 1. On this day, you have 2 copies of 02: 00 - earlier with GMT + 2 and later with GMT + 1.
Since you are working with ZoneIds, not offsets, there is no way to know which of the two instances you want. By default, the first is accepted during conversion. Both 02:00 GMT + 2 and 02:00 GMT + 1 will be converted at 02:00 GMT + 2 if you provide hourOfDay along with ZoneId.
Muhip tezcan
source share