In most of the United States, daylight savings time ends on November 5, 2017 at 02:00 a.m., and we repeat that hour. What is the output of the following?
import java.time.*; public class Main { public static void main(String[] args) { LocalDate localDate = LocalDate.of(2017, 10, 5); LocalTime localTime = LocalTime.of(1, 0); ZoneId zone = ZoneId.of("America/New_York"); ZonedDateTime z = ZonedDateTime.of(localDate, localTime, zone); for (int i = 0; i < 6; i++) z = z.plusHours(1); /* w w w . j a va2 s .co m*/ System.out.println(z.getHour()); } }
C.
The Java 8 date/time APIs count months starting with one rather than zero.
This means localDate is created as October 5, 2017.
This is not the day that daylight savings time ends.
The loop increments the hour six times, making the final time 07:00.
Therefore Option C is the answer.