简体   繁体   English

SimpleDateFormat.parse返回errorIndex为0

[英]SimpleDateFormat.parse returns errorIndex as 0

Using jdk1.7.0_55, I'm getting parseposition.errorIndex as 0 in case of timezone is not standard one. 使用jdk1.7.0_55,如果时区不是标准的,我将parseposition.errorIndex设为0。

But using jdk1.6.0_38 I'm getting parseposition.errorIndex as 21 for the same wrong timezone format 但是使用jdk1.6.0_38对于相同的错误时区格式我得到的parseposition.errorIndex为21

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: 使用jdk 6的结果:

Error Index 21 错误索引21

Result Using jdk 7 使用jdk 7的结果

Error Index 0 错误索引0

Why there is difference in it? 为什么有区别?

Please help 请帮忙

Indeed this is a regression. 确实,这是一种回归。 Still broken in latest Java 8 build. 在最新的Java 8版本中仍未解决。 Public OpenJDK bug tracker does not list it, so I have reported it to Oracle for review. 公开的OpenJDK错误跟踪程序未列出它,因此我已将其报告给Oracle进行审查。 It is tracked by Oracle with Review ID: JI-9021556 Oracle对其进行了跟踪,审阅ID为JI-9021556

Unfortunately there is no way for you to fix that. 不幸的是,您无法解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM