Originally posted by John Todd:
Yes but Timestamp class contains the nano second part which java.util.Date doesn't handle it.
When I'm trying to display the converted Date object (according to my previous posted code), I got:
date info .. 00:00:00 ...
Obviously, I lost the time.
When you convert from timestamp to date, time will not be lost. the problem might be when you get date from database it might truncate time.
see the below eg:
the long value of timestamp, util.date, sql.date will be same. only when it is printed it will be printed in different way. but you are converting into util.date so will not loose time only nano sec. will not come
Timestamp st = new Timestamp(System.currentTimeMillis());
java.util.Date date1 = new java.util.Date(st.getTime());
java.sql.Date date2 = new java.sql.Date(st.getTime());
System.out.println(st); print date,Time, nano sec
System.out.println(date1); print date, time
System.out.println(date2); print date