Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private final static String DATE_FORMAT =("yyyy-MM-dd");
- public void validate(String input) {
- if (input == null || !input.matches("\\d{4}[-]\\d{2}[-]\\d{2}")) {
- throw new InvalidDateFormatException();
- }
- try {
- DateFormat df = new SimpleDateFormat(DATE_FORMAT);
- df.setLenient(false);
- df.parse(input);
- }catch (ParseException e) {
- throw new UnknownDateFormatException();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement