-
Bug
-
Resolution: Duplicate
-
P2
-
None
-
1.2.0
-
generic
-
generic
Name: bb33257 Date: 02/09/99
DateFormat does not parse Feb 29, 2000 when set to strict.
This is probably a problem in the underlying GregorianCalendar
class.
Test code:
import java.util.*;
import java.text.*;
public class feb29 {
public static void main(String[] args) throws ParseException {
String pattern = "MMM d, yyyy";
DateFormat fmt = new SimpleDateFormat(
pattern,
new DateFormatSymbols(Locale.US));
for (int i=0; i<2; ++i) {
fmt.getCalendar().setLenient(i == 0);
System.out.println("Lenient = " + (i == 0));
Date d = new Date(2000-1900, Calendar.FEBRUARY, 29);
String s = fmt.format(d);
System.out.println(d + " x " + pattern +
" => " + s);
ParsePosition pos = new ParsePosition(0);
d = fmt.parse(s, pos);
System.out.println(d + " <= " + pattern + " x " + s);
System.out.println("Parse pos = " + pos);
}
}
}
Output:
Lenient = true
Tue Feb 29 00:00:00 PST 2000 x MMM d, yyyy => Feb 29, 2000
Tue Feb 29 00:00:00 PST 2000 <= MMM d, yyyy x Feb 29, 2000
Parse pos = java.text.ParsePosition[index=12,errorIndex=-1]
Lenient = false
Tue Feb 29 00:00:00 PST 2000 x MMM d, yyyy => Feb 29, 2000
null <= MMM d, yyyy x Feb 29, 2000
Parse pos = java.text.ParsePosition[index=0,errorIndex=12]
(Review ID: 53988)
======================================================================
- duplicates
-
JDK-4209272 Regression: SimpleDateFormat w/lenient mode false, throws exception for Feb 29
-
- Resolved
-