我需要根據指定的格式檢查日期的有效性。谷歌搜索後,我發現一個:格式化日期不適用於Java
public static boolean isThisDateValid(String dateToValidate, String dateFromat){
SimpleDateFormat sdf = new SimpleDateFormat(dateFromat);
sdf.setLenient(false);
ParsePosition position = new ParsePosition(0);
Date date = sdf.parse(dateToValidate,position);
return date != null && position.getIndex() == dateFromat.length();
}
但它不是working..When我跑了這一點,它返回而不是指定false.Month true值是無效的,即13
System.out.println(isThisDateValid("20101331","yyyymmdd"));
我錯過什麼?
謝謝..問題解決了 – Anand
@Anand歡迎您:) – PermGenError