mservidio mservidio - 2 months ago 35
Java Question

Converting java.sql.Date to java.util.Date

What's the simplest way to convert a java.sql.Date object to a java.util.Date while retaining the timestamp?

I tried:

java.util.Date newDate = new Date(result.getDate("VALUEDATE").getTime());

with no luck. It's still only storing the date portion into the variable.

x4u x4u

The class java.sql.Date is designed to carry only a date without time, so the conversion result you see is correct for this type. You need to use a java.sql.Timestamp to get a full date with time.

java.util.Date newDate = result.getTimestamp("VALUEDATE");