How to get the number of milliseconds represented by a java.sql.Time?

STh :

I have a java.sql.Time (00:04:24) from which I want to get the number of milliseconds (or seconds):

ResultSet rs = ...;
java.sql.Time time = rs.getTime("DURATION");
long millis = time.getTime();

But the result are -3336000 instead of 264000.

Click here to see my output.

Why isn't the output 264000?

YCF_L :

If you are using the modern JDBC version, you can use :

LocalTime time = rs.getObject("DURATION", LocalTime.class);
long millis = time.toSecondOfDay() * 1000 + time.get(MILLI_OF_SECOND);

About the calculation of milliseconds, unfortunately, there are no method to get the Milliseconds of the day, for that I used that way.

Or as suggested by @Andreas :

long millis = time.toNanoOfDay() / 1000000

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=277013&siteId=1