public static boolean checkDate(String str) {
boolean bolRet = true;
if (StringUtils.isNotEmpty(str)) {
try {
SimpleDateFormat formatDate = new SimpleDateFormat("yyyy/MM/dd");
// 將某個日期以固定格式轉化成字符串
// String str
= sdf.format(formatDate );
formatDate.setLenient(false);
Calendar calendar = Calendar.getInstance();
java.util.Date date = formatDate.parse(str);
calendar.setTime(date);
int nowYear = calendar.get(Calendar.YEAR);
bolRet = (nowYear >= 2000) && (nowYear <= 9999)
&& formatDate.format(date).equals(str);
} catch (Exception ex) {
bolRet = false;
System.out.println(ex);
}
}
return bolRet;
}
posted on 2008-05-23 15:53
scea2009 閱讀(170)
評論(0) 編輯 收藏