JDK-4791948 : API: method Date.toString() returns unexpected string
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.4.1
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2002-12-11
  • Updated: 2003-09-09
  • Resolved: 2003-09-09
Related Reports
Duplicate :  
Description

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
-----------------------------------

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

Comments
EVALUATION The spec should be: yyyy is the year, as four or more decimal digits ###@###.### 2002-12-13 This problem will be addressed in 4484483. ###@###.### 2003-09-09
13-12-2002