当前位置:编程学习 > C/C++ >>

日期/时间校验(yyyyMMddHHmmss)

 

 

public static boolean checkValidDate(String pDateObj) {   

        try{   

          int year = new Integer(pDateObj.substring(0, 4)).intValue();   

          int month = new Integer(pDateObj.substring(4, 6)).intValue();   

          int date = new Integer(pDateObj.substring(6, 8)).intValue(); 

          int hourOfDay = new Integer(pDateObj.substring(8, 10)).intValue(); 

          int minute = new Integer(pDateObj.substring(10, 12)).intValue(); 

          int second = new Integer(pDateObj.substring(12, 14)).intValue(); 

          Calendar   cal   =   Calendar.getInstance();   

          cal.setLenient(   false   );   //允许严格检查日期格式   

          cal.set(year,   month-1,   date); 

          cal.set(year, month - 1, date, hourOfDay, minute, second); 

          cal.getTime();//该方法调用就会抛出异常   

      }catch(   Exception   e   )   {    

          ret   =   false;   

      }   

      return   ret;   

 }

补充:软件开发 , C语言 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,