In 2015, daylight saving time in New York, USA, begins on March 8th at 2:00 AM. As a result, 2:00 AM becomes 3:00 AM.
Given the code fragment:
Which is the result?
In 2015, daylight saving time in New York, USA, begins on March 8th at 2:00 AM. As a result, 2:00 AM becomes 3:00 AM.
Given the code fragment:
Which is the result?
In the given code, the daylight saving time begins on March 8th, 2015 at 2:00 AM in New York, where 2:00 AM immediately becomes 3:00 AM. The initial time 'dt' is set to '2015-03-08T01:00' in the 'America/New_York' time zone. When adding two hours to this time using 'dt.plusHours(2)', you'll go through the daylight saving change, so the final time 'dt2' will be '2015-03-08T04:00' (skipping 2:00 AM entirely). Consequently, the time difference between 'dt' and 'dt2' is three hours. Therefore, the correct result is '4:00 " difference: 3'.
Answer is D, public class Test { public static void main (String[] args) { ZoneId zone = ZoneId.of("America/New_York"); ZonedDateTime dt = ZonedDateTime.of(LocalDate.of(2015,3,8), LocalTime.of(1,0), zone); ZonedDateTime dt2 = dt.plusHours(2); System.out.print(DateTimeFormatter.ofPattern("H:mm - ").format(dt2)); System.out.print("difference: " + ChronoUnit.HOURS.between(dt,dt2)); } }
D is the correct answer
D is correct.
D. tested