开发者

How to parse from SQL Time (String) to java.sql.Time?

开发者 https://www.devze.com 2023-01-30 20:53 出处:网络
i have a database with a Time field. When i get the fields with a php, i r开发者_Python百科eceive the Time field as a String, by JSON.

i have a database with a Time field. When i get the fields with a php, i r开发者_Python百科eceive 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消