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

API: method Date.toString() returns unexpected string

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 1.4.1
    • core-libs



      Name: vpR10011 Date: 12/11/2002


      J2SE specification of the method java.util.Date.toString() says:
      "public String toString()
          Converts this Date object to a String of the form:
               dow mon dd hh:mm:ss zzz yyyy
          where:
      ...
               yyyy is the year, as four decimal digits..."
          
          
      But if Date object specifies large number of milliseconds since
      the January 1, 1970, 00:00:00 GMT then toString() method returns
      string which contains more than four decimal digits for year representation.
      This representation is corresponding to SimpleDateFormat.format(String)
      specification.
      But specification of toString() method does not refer to SimpleDateFormat.

      Probably it is spec bug.

      To reproduce this bug run the following test:
      ---------------test1.java----------------------------
      import java.util.*;
      import java.text.*;

      public class test1 {
          public static void main (String[] argv) {
              Format sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy",
                                                Locale.US);
              Date dd = new Date(Long.MAX_VALUE - 1);
              String toStr = dd.toString();
              if (toStr.charAt(toStr.length() - 5) != (char)' ' ) {
                  System.out.println("Not four digits: "+dd.toString());
                  System.out.println(" format: "+sdf.format(dd));
              } else {
                  System.out.println("Ok");
              }
          }
      }
      --------------------- Output ------------------------
      % javac -d . test1.java
      % java -version
      java version "1.4.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
      Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)
      % java -classpath . test1
      Not four digits: Sun Aug 17 07:12:55 GMT+06:00 292278994
               format: Sun Aug 17 07:12:55 GMT+06:00 292278994
      -----------------------------------

      ======================================================================

            okutsu Masayoshi Okutsu
            verapsunw Verap Verap (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: