aspose file tools
The moose likes Java in General and the fly likes Interesting TimeZone issue Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Interesting TimeZone issue" Watch "Interesting TimeZone issue" New topic
Author

Interesting TimeZone issue

Nick Hill
Greenhorn

Joined: Dec 19, 2008
Posts: 1
Hello all,

I�ve been stumped on this one for quite some time, and I was curious to see if any of you out there would have a clever solution for it.

Basically, what we�ve got is this:

Object1[ ] = an array of objects returned from an external service. Within these objects, we have a �birthDate� field that is of type �Calendar�. If I look closely at these birthdates, I can see the timezone information is essentially blank (or defaulted, however you want to look at it) as just �GMT�.

Object2[ ] = an array to hold a collection of objects similar (but not completely identical) to Object1[ ]. Looking at the Object2 definition, we also have a �birthDate� field here that is of type �Date� (as in java.util.Date).

To get the data from Object1[ ] to Object2[ ], we�re using a dozer mapping.

So you�re asking �what�s the problem?�

Well, truthfully, when this app runs locally (which for us is US Central Standard Time) there is no problem. The mapping occurs just fine. For example:

Object1[0].Person.birthDate = �05/19/1970 00:00:00 GMT�

Seems to map just fine as:

Object2[0].Person.birthDate = �05/19/1970 00:00:00 CST�

However, we have users of this application all over the country � that�s where the problem comes in: users of this application west of CST encounter this issue (I�ll use Mountain Standard Time as my example):

Object1[0].Person.birthDate = �05/19/1970 00:00:00 GMT�

Maps to:

Object2[0].Person.birthDate = �05/18/1970 23:00:00 MST�

So it�s like something (the JVM?) is trying to account for the hour difference between CST (where the code was written & compiled) and MST (where the end product is being used).

Can anyone think of a clever solution to this? I�ve come up with something that halfway works, but it is a very messy hack fix involving adding the TZ offset back into the �mapped� (Object2[ ].Person.birthDate) date. I�d prefer not to use something like that if there is a more appropriate solution.

Thanks in advance!
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3268

Hi Nick,

If I've read your Q correctly I'm afraid that your 1/2 hack is probably a good a solution as any :| .


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Interesting TimeZone issue
 
Similar Threads
Calendar() / Date() bug ???
DST Problem on client side
Date 01/01/1970 returning non-zero value for time
Date/Time conversion to GMT with DayLightSavings
Enums and switch statements