Friday, 15 March 2019

Validate date format according to the format we want

The following java code/method will return true/false based on the dateformat you pass (against which the date value will be checked):

public static boolean checkDatePattern(String padrao, String data) {
  DateFormat formatter = new SimpleDateFormat(padrao);
  formatter.setLenient(false);
  try {
      Date date= formatter.parse(data);
  } catch (ParseException e) {
      e.printStackTrace();
      return false;
  }
  return true;

 }

No comments:

Post a Comment