I have String value of 08:03:10 pm, and I want to convert it into time. How can I do this in Java?
String str = "08:03:10 pm";
DateFormat formatter = new SimpleDateFormat("hh:mm:ss a");
Date date = formatter.parse(str);
Must See
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With