I trying to get data from database like..
while(rs.next())
{
java.sql.Timestamp t=rs.getTimestamp("date");
}
Now i want to convert Timestamp ‘t’ into java.util.Date type.
In that i’m trying
Date d=new Date(t);//but hear given error
System.out.println(d);
System.out.println(d.toGMTString());
java.sql.Timestampalready extendsjava.util.Date, so you don’t need to do anything:You should read the docs for
Timestampfor details of some potentially-unexpected behaviour though, in particular:(I translate this as “Oops, we used inheritance where we should have used composition.”)
To get around this, you may want to use: