-
Bug
-
Resolution: Fixed
-
P4
-
1.1.7, 1.2.0
-
007
-
generic
-
solaris_2.6
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2023353 | 1.2.2 | Masayoshi Okutsu | P4 | Closed | Fixed | 1.2.2 |
JDK-2023352 | 1.2.1_003 | Masayoshi Okutsu | P4 | Resolved | Fixed | b03 |
JDK-2023351 | 1.1.8 | Masayoshi Okutsu | P4 | Closed | Fixed | 1.1.8 |
JDK-2023350 | 1.1.7 | Masayoshi Okutsu | P4 | Resolved | Fixed | 005 |
The way the negative years are handled using the SimpleDateFormat
and DateFormat classes is strange, even with the setLenient(false)
being called :
format: MM/dd/yyyy or MM/dd/yyy or MM/dd/yy
the year -1 is parsed to 1999
the year -2 is parsed to 1998
.
.
.
the year -9 is parsed to 1991
It doesn't make any sense for the year -1 to be parsed
to 1999 as is the same for the rest (-2 to -9).
------------------------------------------------------
The following test case can be run to verify the above.
/**
* You can change the format string to cater to
* 3 or 4 digit years to check the ouput.
*/
import java.util.*;
import java.text.*;
class t3 {
public static void main(String args[]){
try {
DateFormat formatter = new SimpleDateFormat ("MM/dd/yy");
formatter.setLenient(false);
String s = "02/18/-";
Date d = null;
System.out.println("format string is: MM/dd/yy");
for(int i=1; i<10; i++) {
d = formatter.parse(s+i);
System.out.println(s + i + " parsed to " + d.toString());
}
}
catch(Exception e) {
System.out.println("Format exception" + e);
}
}
}
This also happens in jdk1.1.6.
john.s.lee@Eng 1998-11-02
This continues to happen in jdk1.1.7
This continues to happen in jdk1.1.8h build.
john.s.lee@Eng 1999-02-25
- backported by
-
JDK-2023350 SimpleDateFormat parsing years -1 through -9 to 1999 through 1991.
- Resolved
-
JDK-2023352 SimpleDateFormat parsing years -1 through -9 to 1999 through 1991.
- Resolved
-
JDK-2023351 SimpleDateFormat parsing years -1 through -9 to 1999 through 1991.
- Closed
-
JDK-2023353 SimpleDateFormat parsing years -1 through -9 to 1999 through 1991.
- Closed
- relates to
-
JDK-4162941 java.util.Calendar and java.text.DateFormat documentation needs more clarity.
- Closed