Question

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

Was it helpful?

Solution

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

Must See

OTHER TIPS

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())

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top