How to convert a java.sql.Timestamp to java.util.Date?
416044Aug 26 2004 — edited Aug 26 2004Got 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()?