java.text.ParseException:不可解析的日期:";2014年9月16日“;

java.text.ParseException:不可解析的日期:";2014年9月16日“;,java,Java,我想在mysql表中存储一个日期,我得到java.text.ParseException:不可解析的日期:“09/16/2014”。有人能帮我吗 I have tried in this way: String sdate = request.getParameter("startDate"); DateFormat format = new SimpleDateFormat("dd-MM-yyyy"); Date dateObj = format.parse(sdate); and the

我想在mysql表中存储一个日期,我得到java.text.ParseException:不可解析的日期:“09/16/2014”。有人能帮我吗

I have tried in this way:
String sdate = request.getParameter("startDate");
DateFormat format = new SimpleDateFormat("dd-MM-yyyy");
Date dateObj = format.parse(sdate);

and the formate of "startDate" will be always like "dd/MM/yyyy".
你应该使用

MM/dd/yyyy
而不是

dd-MM-yyyy
如何决定

例如:

这样试试看

try{
String sdate = request.getParameter("startDate");
DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
Date dateObj = format.parse(sdate);
}catch(Exception e){
e.printStackTrace();
}

有关
SimpleDataFormat
的更多信息,请访问。

如果我理解您的意思,您真正需要的是将格式从一种转换为另一种。这可以通过两个
日期格式来完成,例如

输出为

16-09-2014

您尝试分析的日期格式为MM/dd/yyyy:use DateFormat format=new SimpleDateFormat(“MM/dd/yyyy”)@maress no it is
MM/dd/yyyyy
String sdate = "09/16/2014";// request.getParameter("startDate");
DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
DateFormat format2 = new SimpleDateFormat("dd-MM-yyyy");
Date dateObj;
try {
    dateObj = format.parse(sdate);
    System.out.println(format2.format(dateObj));
} catch (ParseException e) {
    e.printStackTrace();
}
16-09-2014