Parsing String to Time and insert in mysqldatabase
Posted
by kawtousse
on Stack Overflow
See other posts from Stack Overflow
or by kawtousse
Published on 2010-04-29T03:45:53Z
Indexed on
2010/04/29
3:57 UTC
Read the original article
Hit count: 341
Goal: Parse a string from an input type text into TIME type to be inserted in MYSQL Database.
String start= request.getParameter("startp");
System.out.println("start:" +start);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
long ms=0;
try {
ms = sdf.parse(start).getTime();
System.out.println(" the value of ms is:" +ms);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Time ts = new Time(ms);
System.out.println("the value of ts is:" +ts);
- start:14:12 (value witch i entered actually in the form at the start field named startp)
- the value of ts is :01:00:00
- java.text.ParseException: Unparseable date: "14:12" at java.text.DateFormat.parse(Unknown Source)
- ms not displayed
I ensure that database type of the following parameter is TIME.
Thanks.
© Stack Overflow or respective owner