java 1.7中SimpleDataFormat中的行为更改?
考虑下面的代码片段java 1.7中SimpleDataFormat中的行为更改?,java,date,datetime,Java,Date,Datetime,考虑下面的代码片段 public class Test1 { public static void main(String[] args) throws ParseException, java.text.ParseException { SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); f.setLenient(false); String dateStr
public class Test1 {
public static void main(String[] args) throws ParseException, java.text.ParseException {
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
f.setLenient(false);
String dateStr = "2008-01-23 00:00:00.0";
Date date=f.parse(dateStr);
System.out.println(date);
}
}
这在Java1.6中运行良好,并提供输出Wed Jan 23 00:00:00 IST 2008
对于Java1.7,它给出了异常
Exception in thread "main" java.text.ParseException: Unparseable date: "2008-01-23 00:00:00.0"
at java.text.DateFormat.parse(DateFormat.java:357)
我认为Java1.7的行为是正确的,因为00:00:00.0不属于hh:mm:ss格式(1-12小时格式)
我的假设是正确的,1.6有bug,并且在1.7中得到了纠正吗?是的,这种行为在Java7中已经改变了。错误修复文档可以在上找到。bug id是JDK-4396385。您的假设是正确的,只是无法立即找到bug