I need convert a String to Date with exact format ( dd/MM/yyyy) I wrote this method :
public static Date toDate(String input, String format) throws DateConverterException {
if (StringUtils.isEmpty(input) || StringUtils.isEmpty(format)) {
throw new DateConverterException (String.format("Input %s or format %s is empty or", input, format));
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
sdf.setLenient(false);
Date date = null;
try {
date = sdf.parse(input);
} catch (ParseException e) {
throw new DateConverterException (e);
}
return date;
}
So if input date is "06/10/" , exception is thrown = good but if input date is "06/10/1" date is constructed despite the format is not respected
Any help would be appreciated Thank you very much