JDK-6205686 : [Fmt-Da] Date formatting classes should support Calendar objects.
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.4.1,1.4.2
  • Priority: P4
  • Status: Resolved
  • Resolution: Won't Fix
  • OS: linux
  • CPU: x86
  • Submitted: 2004-12-08
  • Updated: 2018-08-15
  • Resolved: 2018-08-15
Related Reports
Duplicate :  
Description
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

Comments
Closing this as won't fix as the use of java.time APIs are recommended for date/time operations.
15-08-2018

EVALUATION We should consider a parse method that returns a Calendar object as well.
14-03-2007