What is the output of the following code?
import java.time.LocalDateTime; import java.time.Period; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; public class Main { public static void main(String[] args) { LocalDateTime d = LocalDateTime.of(2015, 5, 10, 11, 22, 33); Period p = Period.ofDays(1).ofYears(2); d = d.minus(p); /* w w w. j ava 2 s . c om*/ DateTimeFormatter f = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT); System.out.println(f.format(d)); } }
B.
Period does not allow chaining.
Only the last Period method called counts, so only the two years are subtracted.