Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6205686

[Fmt-Da] Date formatting classes should support Calendar objects.

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.4.1, 1.4.2
    • core-libs

      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

            nishjain Nishit Jain
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: