Using jdk1.7.0_55, I'm getting parseposition.errorIndex as 0 in case of timezone is not standard one.
But using jdk1.6.0_38 I'm getting parseposition.errorIndex as 21 for the same wrong timezone format
Below is the sample:
String date = "13 Jan 2005 21:45:34 ABC";
String format = "dd MMM yyyy HH:mm:ss z";
ParsePosition pp = new ParsePosition(0);
pp.setIndex(0);
SimpleDateFormat sd = new SimpleDateFormat(format,Locale.ENGLISH);
Date d = sd.parse(date,pp);
System.out.println("Error Index "+pp.getErrorIndex());
Result Using jdk 6:
Error Index 21
Result Using jdk 7
Error Index 0
Why there is difference in it?
Please help
SimpleDateFormat parse() Method in Java with Examples. The parse() Method of SimpleDateFormat class is used to parse the text from a string to produce the Date. The method parses the text starting at the index given by a start position.
SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. It allows for formatting (date → text), parsing (text → date), and normalization. SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting.
The parse () Method of SimpleDateFormat class is used to parse the text from a string to produce the Date. The method parses the text starting at the index given by a start position. Parameters: The method takes two parameters: Attention reader! Don’t stop learning now.
For parsing with the abbreviated year pattern ("y" or "yy"), SimpleDateFormat must interpret the abbreviated year relative to some century. It does this by adjusting dates to be within 80 years before and 20 years after the time the SimpleDateFormat instance is created.
Indeed this is a regression. Still broken in latest Java 8 build. Public OpenJDK bug tracker does not list it, so I have reported it to Oracle for review. It is tracked by Oracle with Review ID: JI-9021556
Unfortunately there is no way for you to fix that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With