How to convert Time type to String?

0

I have a horaConsulta field and I can not convert it to String

DAO

stmt.setTime(4, new java.sql.Time(consulta.getHoraConsulta().getTime()));

Servlet

Time horaConsulta = converterTime(request.getParameter("horaConsulta").replace(":", ":"));

    
asked by anonymous 19.07.2015 / 19:28

1 answer

4

If I understood your question is transforms Dates and Times into and vice versa Strings, an easy way to do is using SimpleDateFormat, passing a string with time format. The reverse is also possible.

Example

DateFormat formatter = new SimpleDateFormat("HH:mm:ss"); //Hora, minuto, segundo.
formatter.format(new Date()); // Deverá mostrar hora atual em string
DateFormat parser = new SimpleDateFormat("DD/mm/YYYY HH:mm:ss");
Date date = parser.parse("21/02/1987 02:02:00"); // Deverá transformar a string em Date se a data estiver no padrão

How to convert date into string and date new

SimpleDateFormat Class Documentation

DateFormat Class Documentation

    
20.07.2015 / 15:25