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:
b)
Relevant letters and their meaning:
d Day in month E Day name in week M Month in year Y Year
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.