Question

hi i am passing my date time string using get method in apache servlet and it goes like this

http://localhost:8084/example/Time_ser?date=15/03/2013%2004:14:30%20PM

and i am using

String time=request.getParameter("date");

to get the date value.....

and my java code to convert the string to timestamp is given below

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());

but it shows error like this

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

am i doing anything wrong please help me..........

Was it helpful?

Solution

use / not - because you date is formatted as 15/03/2013 04:14:30 PM.

DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top