How to convert string into Time object in Java?

Chamal picture Chamal · Jan 3, 2011 · Viewed 36k times · Source

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

Answer

Jigar Joshi picture Jigar Joshi · Jan 3, 2011
 String str = "08:03:10 pm";
 DateFormat formatter = new SimpleDateFormat("hh:mm:ss a");
 Date date = formatter.parse(str);

Must See