java - Convert plain string to time -
this question has answer here:
- java string date conversion 13 answers
i have string value need convert time , save in mysql.[the column's datatype time in database table] examples of string values might encounter convert time object are:
string time = "5:32 pm";
string time = "12:00 am";
string time = "11:43 pm";
i browsed few examples pulled time date object couldn't find apt example, such in case convert plain string. main reason need convert time save in mysql.
you can convert java.sql.date
:
string str = "5:32 pm"; dateformat formatter = new simpledateformat("hh:mm a"); java.util.date date = (java.util.date)formatter.parse(str); java.sql.date sqldate = new java.sql.date(date.gettime());
if need java.sql.time
, :
java.sql.time time = new java.sql.time(date.gettime());
and use preparedstatement#settime().
Comments
Post a Comment