Код: Выделить всё
public Timestamp convertFromDate(String fromDate) throws ParseException {[b] String[] possibleFormats = { "dd/MM/yyyy", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd" };
ParseException lastException = null;
for (String format : possibleFormats) {
try {
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
dateFormat.setLenient(false);
Date parsedDate = dateFormat.parse(fromDate);
return new Timestamp(parsedDate.getTime());
} catch (ParseException e) {
lastException = e;
}
}
throw lastException;
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... 1899-12-30