Created
February 12, 2014 08:33
-
-
Save pinzolo/8951882 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 指定の表現が指定されたパターンの日付として妥当かどうかを判別する。 | |
* @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