String dateimput=request.getParameter("datepicker");
System.out.printl("datepicker:" +dateimput);
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
Date dt = null;
try
{
dt = df.parse(dateimput);
System.out.println("date imput is:" +dt);
} catch (ParseException e)
{
e.printSt开发者_StackOverflow社区ackTrace();
}
*datepicker:04/29/2010 (value I currently selected from datepicker). *the field in database is typed date. 1-date imput is:Thu Apr 29 00:00:00 CEST 2010 and in database level it is inserted like that 01/01/0001 00:00:00
Your Java code will work fine.
04/29/2010 will give you a date object with the correct time/date set.
You said the problem is during the Database insert, so you should tell us the used database and post the code you are using for the insert.
Based on your comment to echox's answer. It looks like your problem might be not putting quotes around your date value in your insert statement.
精彩评论