在mysql数据库中插入日期 [英] insert a date in mysql database
本文介绍了在mysql数据库中插入日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用jquery datepicker,然后像这样在我的servlet中读取它:
I use a jquery datepicker then i read it in my servlet like that:
字符串dateimput = request.getParameter("datepicker");//1 然后像这样解析它:
String dateimput=request.getParameter("datepicker");//1 then parse it like that:
System.out.println("datepicker:" +dateimput);
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
java.util.Date dt = null;
try
{
dt = df.parse(dateimput);
System.out.println("date imput parssé1 est:" +dt);
System.out.println("date imput parsée2 est:" +df.format(dt));
} catch (ParseException e)
{
e.printStackTrace();
}
并插入查询:
String query = "Insert into dailytimesheet(trackingDate,activity,projectCode) values ("+df.format(dt)+", \""+activity+"\" ,\""+projet+"\")";
它成功通过直到现在,但是如果我检查插入的记录,我发现了日期: 01/01/0001 00:00:00
it pass successfully untill now but if i check the record inserted i found the date: 01/01/0001 00:00:00
我已经尝试修复它,但对我来说还是一团糟.
l've tried to fix it but it still a mess for me.
推荐答案
您必须以以下格式传递日期:"yyyy-MM-dd"
You have to pass the Date in the format: "yyyy-MM-dd"
这篇关于在mysql数据库中插入日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文