Reputation: 1
I have a String
"02:30" for example. 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 ???
Upvotes: 0
Views: 1149
Reputation:
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.
Upvotes: 1