String dateString = request.getParameter("pickerDate"); //dateString "15-03-2013"
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
format = new SimpleDateFormat("dd-MMM-yy");
Date sdf = null;
try {
Date date = format.parse(dateString);
System.out.println(format.format(date));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I am getting the date from date Picker. But I get an unparsable exception. Any help on how to convert the string "15-03-2013" to store it in the Database as a Date?
Thanks
You are overwriting your first SimpleDateFormat
with a second one.
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
format = new SimpleDateFormat("dd-MMM-yy");
The second one is looking for MMM
, i.e. a three-character month name. Just delete that second line.