code: private static boolean isValidDate(String date, Calendar out, String separator) {
          try {
              String[] dates = date.split(separator);
              out.set(Calendar.DATE, Integer.parseInt(dates[dates.length - 1]));
              out.set(Calendar.MONTH, Integer.parseInt(dates[dates.length - 2]));
              if (dates.length > 2) {
                  out.set(Calendar.YEAR, Integer.parseInt(dates[dates.length - 3]));
              }
          } catch (Exception e) {
              try {
                  out.set(Calendar.DATE, Integer.parseInt(date.substring(date.length() - 2, date.length())));
                  out.set(Calendar.MONTH, Integer.parseInt(date.substring(date.length() - 4, date.length() - 2)) - 1);
                  if (date.length() > 4) {
                      out.set(Calendar.YEAR, Integer.parseInt(date.substring(date.length() - 8, date.length() - 4)) - 1);
                  }
              } catch (Exception e2) {
                  return false;
              }
          }
  
          return true;
      }
docs: To check if the input date string is valid and match with the required
  format
  
  @param date The input date string, which should comes with the format of
  yyyy-mm-dd, the separator should be same with the third parameter
  @param out The Calendar instance which will be assigned with input year,
  month and day
  @param separator The separator string used in date format
  @return check result