I have a constructor that takes a Date input in this format "Nov 15 2015" then i use below method to convert it to an SQL date format. When i read from the DB I convert it back to java.util.Date to be stored in the bean.
public static java.sql.Date inDate(String Date) {
String startDateInput = Date;
try {
// Start Date
String sDate = new SimpleDateFormat("yyyy-MM-dd")
.format(new SimpleDateFormat("MMM dd yyyy").parse(startDateInput));
java.sql.Date starDate = new java.sql.Date(new SimpleDateFormat("yyyy-MM-dd").parse(sDate).getTime());
return starDate;
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
My Question is how can i check if the date was entered in this format "Nov 15 2015" and if not throw an exception?