• Post Reply Bookmark Topic Watch Topic
  • New Topic

java Util Date problem  RSS feed

 
Jayesh Netravali
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
We have our server set to the GMT time zone and our client is set to the EST time zone. We are getting a date field from the database as follows:-
java.util.Date dtUtil = null;
String strDate = rs.getString( "DATE");
if ( null != strDate ){
dtUtil = new java.util.Date( strDate );
}
This dtUtil forms an attribute of a serialized object. When this object is passed over to the client end the date is decremented by one day. Why does this happen?
The java docs for util date do not mention anything specific about the time zone. ( FYI there is a time difference of 5:30 mins b/w the two time zones. Even if the date on both the machines is the same with a time difference of 5:30 this problem still occurs)
How does the date get decremented by one day on deserializing at the client end.
Thanks in advance,
Jayesh.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Timezone is in the mix here. We had exactly the same problem. Java does some magic for you (like it or not). Date uses a DateFormat and the DateFormat has a TimeZone. Has anybody made a custom Date that uses a project DateFormat all the time instead of getting the timezone from the system? We had only one or two problem spots, and I think somebody turned the date into a string so it wouldn't be shifted.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayesh,
Allow me to suggest my JavaWorld article about managing timeones in java.
Good Luck,
Avi.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!