[英]Convert String to java.sql.Time and java.sql.Time to Double
I have a String
"02:30" for example. 例如,我有一个
String
“ 02:30”。 I want to convert it to java.sql.Time
, from java.sql.Time
then convert it again to double
, so be 2.5 hours ..... What is the best solution for it ??? 我想将其从
java.sql.Time
转换为java.sql.Time
,然后再次将其转换为double
,所以需要2.5个小时.....什么是最佳解决方案?
This is your code: 这是您的代码:
public static void main(String[] args) {
String res="02:30";
Time tm=new Time(Integer.valueOf(res.split(":")[0]), Integer.valueOf(res.split(":")[1]), 0);
Double dbl=new Double(tm.getHours()+Math.floor(tm.getMinutes()*100/60)/100);
System.out.println(dbl.toString());
}
Note The constructor Time(int, int, int) is deprecated, we should use long
instead. 注意不建议使用构造函数Time(int,int,int),我们应该改用
long
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.