Skip to content

Instantly share code, notes, and snippets.

@pinzolo
Created February 12, 2014 08:33
Show Gist options
  • Save pinzolo/8951882 to your computer and use it in GitHub Desktop.
Save pinzolo/8951882 to your computer and use it in GitHub Desktop.
/**
* 指定の表現が指定されたパターンの日付として妥当かどうかを判別する。
* @param expr 文字列による日付表現
* @param pattern フォーマットパターン
* @return 妥当ならば true
* @throws ParseException パース失敗
*/
public static boolean isValidAsDate(String expr, String pattern) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
// null チェックだと 2013-02-31 -> 2013-03-03 となって valid となるので、再度フォーマットして元と比較する
return expr.equals(sdf.format(sdf.parse(expr)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment