Skip to content

Instantly share code, notes, and snippets.

@Goldbones
Created January 30, 2015 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Goldbones/80deecc6b651134c49cf to your computer and use it in GitHub Desktop.
Save Goldbones/80deecc6b651134c49cf to your computer and use it in GitHub Desktop.
easiest way to see if a String like 12-03-1999 12:12:21 matches a list of dateFormats?
List<SimpleDateFormat> dateFormats = new ArrayList<>();
dateFormats.add(new SimpleDateFormat("dd-MM-yyyy hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("dd/MM/yyyy hh:mm:ss"));
dateFormats.add(new SimpleDateFormat("dd/MM/yyyy"));
dateFormats.add(new SimpleDateFormat("dd-MM-yyyy"));
Example:
12-03-1999 12:12:21-> is valid
12-03-1999-> is valid
12-15-231321-> is invalid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment