Java OCA OCP Practice Question 2684

Question

Consider the following program:

String dateFormat = "d '('E')' MMM, YYYY";
// assume today's date is October 28th 2012
System.out.printf("%s", new SimpleDateFormat(dateFormat).format(new Date()));

This code segment prints the following:

  • a) 28 (44) Oct, 2012
  • b) 28 (Sun) Oct, 2012
  • c) 28 '(Sunday)' Oct, 2012
  • d) 28 (7) Oct, 2012


b)

Relevant letters and their meaning:

d   Day in month
E   Day name in week
M   Month in year
Y   Year

Note

Calling new Date(); object creates a Date object for the current date.

Within the date format string "d '('E')' MMM, YYYY", the opening and closing parenthesis are given within single quotes (i.e., '( 'E')' to ensure that it is not treated as a format specifier character), so the single quotes are not part of the output itself.




PreviousNext

Related