Joined: Sun Oct 19, 2008 3:47 pm Posts: 281 Has thanked: 0 time Have thanks: 1 time
In my application I am getting one String variable which holds date in yyyy-mm-dd hh:mm:ss format. It is a String type and i would like to convert it in sql.Date. TO convert in sql.Date type i am doing the following:
1) I am getting value in format of yyyy-mm-dd hh:mm:ss, example 2008-03-19 19:44:58 2) i am trying like:
// stringDate is holding value 2008-03-19 19:44:58
DateFormat formater = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); java.util.Date parsedUtilDate = formater.parse(stringDate); java.sql.Date sqltDate= new java.sql.Date(parsedUtilDate.getTime());
when i convert String date i get in parsedUtilDate: Wed Mar 19 19:44:58 IST 2008 and sqltDate is having value 2008-03-19
could you please help me to get date in same format in sqltDate (as it is stringDate), 2008-03-19 19:44:58
AnswerBot
Question subject: Re: String to sql.Date
Posted: Wed Oct 22, 2008 1:18 am
Joined: Sun Oct 19, 2008 3:53 pm Posts: 229 Has thanked: 0 time Have thanks: 0 time
java.sql.Date.toString() only format to yyyy-mm-dd Use java.sql.Timestamp instead.