nerdexam
Oracle

1Z0-819 · Question #108

Given: LocalDate dl = LocalDate.of(1997, 2, 7); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("/Insert code here/"); System.out.println(dtf.format(dl)); Which pattern formats the date as…

The correct answer is D. eeee d"th of MMMM yyyy". Option D correctly uses d (single digit) to print "7" rather than zero-padded "07", and MMMM (four M's) to produce the full month name "February" rather than the abbreviated "Feb" - both are required to match the target output "Friday 7th of February 1997". Option A fails on…

Working with Java Data Types

Question

Given: LocalDate dl = LocalDate.of(1997, 2, 7); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("/Insert code here/"); System.out.println(dtf.format(dl)); Which pattern formats the date as Friday 7th of February 1997?

Options

  • Aeeee dd"th of" MMM yyyy"
  • Beeee d"th of" MMMM yyyy"
  • Ceeee d"th of" MMMM yyyy"
  • Deeee d"th of MMMM yyyy"

How the community answered

(25 responses)
  • A
    8% (2)
  • B
    16% (4)
  • C
    4% (1)
  • D
    72% (18)

Explanation

Option D correctly uses d (single digit) to print "7" rather than zero-padded "07", and MMMM (four M's) to produce the full month name "February" rather than the abbreviated "Feb" - both are required to match the target output "Friday 7th of February 1997".

Option A fails on two counts: dd forces a two-digit day ("07") and MMM (three M's) abbreviates the month to "Feb", so neither the day nor the month would match. Options B and C are distractors that differ from D only in quote placement - improperly positioned or unmatched literal delimiters cause the formatter to either throw a parse exception or produce garbled output (e.g., a trailing unmatched quote breaks the pattern string).

Memory tip: Think "more M's = more letters in the month name" - M/MM = numeric (2/02), MMM = abbreviated text (Feb), MMMM = full text (February). The same logic applies to day-of-week: E/EEE = short (Fri), EEEE/eeee = full (Friday). For the day-of-month, d = as-is (7), dd = zero-padded (07).

Topics

#DateTimeFormatter#date formatting#pattern symbols#LocalDate

Community Discussion

No community discussion yet for this question.

Full 1Z0-819 Practice