之前都没注意过有这么个方法,否则判断日期格式就太不靠谱了。
又是晦涩的单词:setLenient(false),严格匹配日期格式
SimpleDateFormat df = new SimpleDateFormat("MMddyyyy");
/*
* With lenient parsing, the parser may use heuristics to interpret inputs that
* do not precisely match this object's format.
* With strict parsing, inputs must match this object's format.
*/
df.setLenient(false);
try {
Date a = df.parse("23232011");
System.out.print("date: " + a);
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}