ZonedDateTime class represents a datetime with time zone rules.
The time zone rules include a zone offset and rules for its variation because of Daylight Saving Time.
The relationships between a ZonedDateTime and a LocalDateTime can be represented as
ZonedDateTime = LocalDateTime + ZoneId
The following is an example of creating a ZonedDateTime from a LocalDateTime:
import java.time.LocalDateTime; import java.time.Month; import java.time.ZoneId; import java.time.ZonedDateTime; public class Main { public static void main(String[] args) { ZoneId usCentral = ZoneId.of("America/Chicago"); LocalDateTime ldt = LocalDateTime.of(2012, Month.MAY, 11, 7, 30); ZonedDateTime zdt = ZonedDateTime.of(ldt, usCentral); System.out.println(zdt);//ww w . j a va 2 s . c o m } }
If the local datetime falls in the middle of the gap, the time is moved forward by the same amount as the gap.
If the local datetime falls in the middle of the overlap, the time is valid.