cerulean

DateFormat setLenient

之前都没注意过有这么个方法,否则判断日期格式就太不靠谱了。
又是晦涩的单词: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();
        }

posted on 2011-07-18 17:23 cerulean 阅读(3181) 评论(0)  编辑  收藏 所属分类: Java


只有注册用户登录后才能发表评论。


网站导航:
 

导航

<2011年7月>
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

统计

常用链接

留言簿(3)

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜