i have a database with a Time field. When i get the fields with a php, i receive the Time field as a String, by JSON.
The string i recive is like this: 08:00:00
ok, all work's fine here, but i need to have that String in java.sql.Time format.
There is a easy way to do it?
code:
String hour1=retrieveHourFromPHPSqlConnection();
Time a=hour1;
how to transform hour1 into Time?
thanks
You can use the following code for changing the String value into the time equivalent: String str = "08:03:10 pm"; DateFormat formatter = new SimpleDateFormat("hh:mm:ss a"); Date date = (Date)formatter. parse(str);
Time is used in the JDBC API, as a wrapper around java. util. Date that handles SQL specific requirements. This class exists to represent SQL TIME, which keeps time without date.
From Javadoc I suggest you to use this :
java.sql.Time myTime = java.sql.Time.valueOf(hour1);
Takes a String in hh:mm:ss format and gives you a java.sql.Time object.
It's valid at least from Java 1.4.2 up to Java 7.
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