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!

java.sql.Date truncates the time part of the date. How can I prevent this?

843854Nov 18 2002 — edited Nov 18 2002
Hi there. I have the problem that when I create a new sql.Date, the time portion of the date seems to be truncated. How can I prevent this?

This is what I do:
I create both util.Date and sql.Date with the long constructor value of 1036398180000 as a parameter. (Or 1036398180 * 1000 which =1036398180000 to prevent the "integer number too large" error. This long value is equal to the date: 4 Nov 2002 10:23:00.

Create a new date with java.util.Date:
java.util.Date dd = new java.util.Date(1000 * (long)1036398180);
System.out.println(dd.toString());
Gives: "Mon Nov 04 10:23:00 GMT+02:00 2002"

Create a new date with java.sql.Date:
java.sql.Date sd = new java.sql.Date(1000 * (long)1036398180);
System.out.println(sd.toString());
Gives: "2002-Nov-04"
??? Where did the time go?

Your help will be greatly appreciated. Probably one of those little things I'm over looking. :)
Thanx much.

Quigrim
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 16 2002
Added on Nov 18 2002
7 comments
1,178 views