Pergunta

I have String value of 08:03:10 pm, and I want to convert it into time. How can I do this in Java?

Foi útil?

Solução

 String str = "08:03:10 pm";
 DateFormat formatter = new SimpleDateFormat("hh:mm:ss a");
 Date date = formatter.parse(str);

Must See

Outras dicas

If you omit the period, it is very easy. Just call the java.sql.Time.valueof() method instead of the Time time = new Time("20:03:10"); method.

Time does not have a contractor that takes long so use time.set(date.getTime())

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top