/** * @param date(2015092510) * @return * 功能:校验日期 */ public boolean validateDate(String date){ boolean result = false; try { if(date!=null&&!"".equals(date)&&date.length()==10){ String year = date.substring(0, 4); String month = date.substring(4, 6); String day = date.substring(6, 8); String hour = date.substring(8); if(year.matches("^[0-9]*[1-9][0-9]*$")&&month.matches("^[0-9]*[1-9][0-9]*$")&&day.matches("^[0-9]*[1-9][0-9]*$")&&hour.matches("^\\d+$")){ int y = Integer.parseInt(year); int m = Integer.parseInt(month); int d = Integer.parseInt(day); int h = Integer.parseInt(hour); if(y>=1900&&y<=2999){ if(m>=1&&m<=12){ if(h>=0&&h<=23){ if(m==1||m==3||m==5||m==7||m==8||m==10||m==12){ if(d>=1&&d<=31){ result = true; } } else if(m==4||m==6||m==9||m==11){ if(d>=1&&d<=30){ result = true; } } else if(m==2){ if(y%4==0){ if(d>=1&&d<=29){ result = true; } } else { if(d>=1&&d<=28){ result = true; } } } } } } } } } catch (RuntimeException e) { throw e; } return result; }
java 日期校验
猜你喜欢
转载自963084302.iteye.com/blog/2246233
今日推荐
周排行