在servlet java中将字符串转换为Mysql时间戳

在servlet java中将字符串转换为Mysql时间戳,java,mysql,apache,java-server,Java,Mysql,Apache,Java Server,嗨,我在ApacheServlet中使用get方法传递日期时间字符串,如下所示 http://localhost:8084/example/Time_ser?date=15/03/2013%2004:14:30%20PM 我正在使用 String time=request.getParameter("date"); 要获取日期值 下面给出了将字符串转换为时间戳的java代码 DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:

嗨,我在ApacheServlet中使用get方法传递日期时间字符串,如下所示

http://localhost:8084/example/Time_ser?date=15/03/2013%2004:14:30%20PM
我正在使用

String time=request.getParameter("date");
要获取日期值

下面给出了将字符串转换为时间戳的java代码

DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss aa");
java.util.Date date = (java.util.Date)formatter.parse(time);
Timestamp timets = new Timestamp(date.getTime());
但它显示了这样的错误

java.text.ParseException: Unparseable date: "15/03/2013 04:14:30 PM"

我做错了什么吗请帮我………

使用
/
而不是
-
,因为您的日期格式为
15/03/2013 04:14:30 PM

DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");

使用
/
而不是
-
,因为您的日期格式为
15/03/2013 04:14:30 PM

DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");

下面的答案是正确的。另外,你不需要那个演员。下面的答案是正确的。而且,你不需要那个演员。