Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.49 KB | None | 0 0
  1. private final static String DATE_FORMAT =("yyyy-MM-dd");
  2.  
  3.     public void validate(String input) {
  4.         if (input == null || !input.matches("\\d{4}[-]\\d{2}[-]\\d{2}")) {
  5.             throw new InvalidDateFormatException();
  6.         }
  7.  
  8.         try {
  9.             DateFormat df = new SimpleDateFormat(DATE_FORMAT);
  10.             df.setLenient(false);
  11.             df.parse(input);
  12.  
  13.         }catch (ParseException e) {
  14.             throw new UnknownDateFormatException();
  15.         }
  16.  
  17.  
  18.  
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement