Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to convert a java.sql.Timestamp to java.util.Date?

416044Aug 26 2004 — edited Aug 26 2004
Got ya! You thought this is a beginner question because java.sql.Timestamp extends java.util.Date. But I want a real java.util.Date object, i.e. a Date object that is an instance of Date and not of Timestamp (anymore).

The reason?

My code compares several dates (all declared with java.util.Date) with each other via the Date.equals() method. I found out, the my code failed for specific equals() calls, when one of the two date objects is an instanceof java.sql.Timestamp. This is probably because the equals() method in Timestamp is overwritten and returns false if the nanoseconds not match. The Timestamp objects are returned from the database (jTDS driver). So, how can i compare Dates with Timestamps without a lot of if ... instanceof ... etc.? I thought i somehow can convert the Timestamp object into a "real" Date object that i can compare with equals()?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 23 2004
Added on Aug 26 2004
4 comments
908 views