-2
java.util.Date tempin = pLabIn.getDate();            
System.out.println(tempin);    

java.util.Date tempout = pLabOut.getDate();   

java.sql.Date labIn = new java.sql.Date(tempin.getTime());    
System.out.println(labIn);    

java.sql.Date labOut = new java.sql.Date(tempout.getTime());

The first System.out shows "Thu Feb 27 22:50:06 PKT 2014" and the second "2014-02-27"

So it miss time. I want to take time as well.

Baz
  • 36,440
  • 11
  • 68
  • 94

2 Answers2

4

Use a java.sql.Timestamp instead.

qqilihq
  • 10,794
  • 7
  • 48
  • 89
2

The toString() implementation for java.sql.Date will only give you the date in the format year-month-day.

This is also precised in the documentation:

Formats a date in the date escape format yyyy-mm-dd.

If you want to keep the time in your print statement, you can use a SimpleDateFormat instead.

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(sdf.format(labIn));
Alexis C.
  • 91,686
  • 21
  • 171
  • 177
  • i have to use this "labIn" in oracle db, and there java.util.date does not insert, so i have to convert it to java.sql.date. BUT i need time and date both – user3190582 Feb 14 '14 at 18:38
  • 1
    @user3190582 You seems to confond the String representation and the date object itself. The string representation of the date object will only print the year-month-day, but the date object itself won't "loose" the time. – Alexis C. Feb 14 '14 at 18:40
  • sorry, i understand what you are saying, but there is problem that in my oracle db table all entries have same time (12:00:00 AM), thats why i thought time is getting missed – user3190582 Feb 14 '14 at 18:49
  • @user3190582 If the time were loosing, I think you will have 00:00:00AM. So the problem might be somewhere else. – Alexis C. Feb 14 '14 at 18:50