[英]How to parse from SQL Time (String) to java.sql.Time?
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. 当我用php获取字段时,我通过JSON接收时间字段作为字符串。
The string i recive is like this: 08:00:00
我回忆的字符串是这样的: 08:00:00
: 08:00:00
: 08:00:00
ok, all work's fine here, but i need to have that String in java.sql.Time format. 好的,这里的所有工作都很好,但我需要java.sql.Time格式的字符串。
There is a easy way to do it? 有一个简单的方法吗?
code: 码:
String hour1=retrieveHourFromPHPSqlConnection();
Time a=hour1;
how to transform hour1 into Time? 如何将hour1转换为时间?
thanks 谢谢
From Javadoc I suggest you to use this : 从Javadoc我建议你使用这个:
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. 采用hh:mm:ss格式的String,并为您提供java.sql.Time对象。
It's valid at least from Java 1.4.2 up to Java 7. 它至少从Java 1.4.2到Java 7都有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.