Java SE 11 Developer — Question 19
Given:
LocalDate d1 = LocalDate.of(1997,2,7);
DateTimeFormatter dtf =
DateTimeFormatter.ofPattern( /*insert code here*/ );
System.out.println(dtf.format (d1));
Which pattern formats the date as Friday 7th of February 1997?
Answer options
- A. “eeee dd+”th of”+ MMM yyyy”
- B. “eeee dd'th of' MMM yyyy”
- C. “eeee d+”th of”+ MMMM yyyy”
- D. “eeee d’th of’ MMMM yyyy”
Correct answer: B
Explanation
The correct answer is B because it properly uses the single quotes to include 'th' as a literal string after the day, ensuring the format matches the desired output. Options A and C incorrectly use the '+' operator, which is not valid in this context, while D incorrectly uses a different quote character that does not match Java's string literal syntax.