Two Laptop Bag
The moose likes JDBC and Relational Databases and the fly likes Date difference between Java and db2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Date difference between Java and db2" Watch "Date difference between Java and db2" New topic
Author

Date difference between Java and db2

Julien Martin
Ranch Hand

Joined: Apr 24, 2004
Posts: 384
Hello,

I am quite puzzled. I have the following environment:

-iseries DB2
-Jdk 1.5
-Hibernate 3 (jpa)
-Tomcat 5.5

When I have "31st December 2006" in the database, the webapp displays "30th December 2006" and so on.

I don't understand this one-day difference???

Does anyone has some clue of why I get this?

Thanks in advance,

Julien.

PS: The fields are typed java.util.Date
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19726
    
  10

That suggests to me that the timezone for the database is not the same as the timezone for the JDK. This could happen even if both of them are running on the iSeries.
Julien Martin
Ranch Hand

Joined: Apr 24, 2004
Posts: 384
That is exactly the case Paul: Db2 is in Chicago and Tomcat in Paris. What do you suggest I do in order to avoid this problem bearing in mind I can't put my Tomcat in Chicago?
Julien.
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3740
    
  10

Don't use Dates, use Calendar objects where you can set the time zone and locale.


[OCA 8 Book] [Blog]
Julien Martin
Ranch Hand

Joined: Apr 24, 2004
Posts: 384
Thanks to both of you!
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Date difference between Java and db2
 
It's not a secret anymore!