A DESCRIPTION OF THE REQUEST :
Using a Calendar object in a DateFormat.format call results in a runtime error.
JUSTIFICATION :
The Date object is almost completely useless, since most of it's methods have been deprecated. Instead, we now use Calendar objects. These should be supported directly in the formatting classes, rather than forcing a convertsion to Date via the getTime() method.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A call like
new SimpleDateFormat("yyyy.MM.dd").format(new GregorianCalendar());
should work, printing today's date in the format specified.
ACTUAL -
java.lang.IllegalArgumentException: Cannot format given Object as a Date
---------- BEGIN SOURCE ----------
new SimpleDateFormat("yyyy.MM.dd").format(new GregorianCalendar());
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
new SimpleDateFormat("yyyy.MM.dd").format(new GregorianCalendar().getTime());
###@###.### 2004-12-08 10:20:43 GMT
Using a Calendar object in a DateFormat.format call results in a runtime error.
JUSTIFICATION :
The Date object is almost completely useless, since most of it's methods have been deprecated. Instead, we now use Calendar objects. These should be supported directly in the formatting classes, rather than forcing a convertsion to Date via the getTime() method.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A call like
new SimpleDateFormat("yyyy.MM.dd").format(new GregorianCalendar());
should work, printing today's date in the format specified.
ACTUAL -
java.lang.IllegalArgumentException: Cannot format given Object as a Date
---------- BEGIN SOURCE ----------
new SimpleDateFormat("yyyy.MM.dd").format(new GregorianCalendar());
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
new SimpleDateFormat("yyyy.MM.dd").format(new GregorianCalendar().getTime());
###@###.### 2004-12-08 10:20:43 GMT
- duplicates
-
JDK-4808661 [Fmt-Da] Add another formatting option to SimpleDateFormat for week-based year
- Closed