Given the code fragment:
<code>
SimpleDateFormat sdf;
</code>
Which code fragment displays the two-digit month number?
A.
sdf = new SimpleDateFormat (“mm”, Locale.UK);
System.out.printIn ( �Result: � + sdf.format(new Date()))
B.
sdf = new SimpleDateFormat (“MM”, Locale.UK);
System.out.printIn ( �Result: � + sdf.format(new Date()))
C.
sdf = new SimpleDateFormat (“MMM”, Locale.UK);
System.out.printIn ( “Result: “+ sdf.format(new Date()))
D.
sdf = new SimpleDateFormat (“MMMM”, Locale.UK);
System.out.printIn (“Result:”+ sdf.format(new Date()))
Explanation:
B: Output example (displays current month numerically): 04
Note:SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date -> text), parsing (text -> date), and normalization.
SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting. However, you are encouraged to create a date-time formatter with either getTimeInstance, getDateInstance, orgetDateTimeInstance in DateFormat. Each of these class methods can return a date/time formatter initialized with a default format pattern. You may modify the format pattern using the applyPattern methods as desired.