Reputation: 1127
I have String value of 08:03:10 pm, and I want to convert it into time. How can I do this in Java?
Upvotes: 11
Views: 37950
Reputation: 765
Time does not have a contractor that takes long so use time.set(date.getTime())
Upvotes: 1
Reputation: 240996
String str = "08:03:10 pm";
DateFormat formatter = new SimpleDateFormat("hh:mm:ss a");
Date date = formatter.parse(str);
Must See
Upvotes: 26
Reputation: 21300
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.
Upvotes: 6