Can you please help in the below matter:
I am having an error in the display is that when I am converting to milliseconds it will show wrong values. Iam using getTime() in Java.
My code is:
Time absent = rs.getT开发者_如何学Cime("abs_hours");
long absent_cumm= (absent.getTime() );
out.println(absent); // This will display 00:04:00 which is correct
But when I am printing absent_cumm
out.println(absent_cumm);// This will display -10560000 which is wrong
How to convert the absent value into milliseconds?
Well, here's at least one way that could work:
Time time = Time.valueOf("00:04:00"); // replace with rs.getTime()
Calendar cal = Calendar.getInstance();
cal.setTime(time);
int hour = cal.get(Calendar.HOUR);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
int ms = (hour * 3600 + minute * 60 + second) * 1000;
System.out.println("ms: " + ms);
Should correctly print "ms: 240000"
精彩评论