2
考虑下面的代码片段java 1.7中SimpleDateFormat的行为改变?
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);
}
}
这部作品在Java 1.6的罚款,并给出输出周三年01月23日00:00:00北京时间2008年
在java中1.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)
我认为JAVA 1.7行为是正确的,因为00:00:00.0不属于hh:mm:ss格式(1-12小时格式)
我的假设是正确的,1.6有错误并在1.7中得到纠正?
你的假设是正确的,只是无法找到bug –