String conversion of time to Java.Sql.Time

Hello,

Im developing a servlet based application where I need to take the time from the user in the hh:mm format and then add it to the database ( MS SQL Server 2000) . I do so via a HTML page.

Now in my servlet I retrieve the value using request.getParameter which gets retrieved as String.So now I need to convert it to the Time format so that I can add it to the DB.

Can someone please guide me as to how this is done, Ive tried SimpleDateFormat but Im not quite clear with that concept and so I think Ive messed it up. Hence Im not posting anything here.

Please help me out.

Thanks in advance.

null

[647 byte] By [DT1a] at [2007-11-26 23:44:36]
# 1

String dateStr = "15:00";

SimpleDateFormat format = new SimpleDateFormat("HH:mm");

try {

Date date = format.parse(dateStr);

System.out.println("date: " + date);

Time t = new Time(date.getTime());

System.out.println("date: " + date);

} catch (ParseException e) {

}

abc0xyza at 2007-7-11 15:16:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
In last System.out I wanted to show you the time.Notice that there is no information related to client timezone. If you need that you must do some additional work.
abc0xyza at 2007-7-11 15:16:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Thanks it worked and it has helped me a lot. Regards.
DT1a at 2007-7-11 15:16:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...