Forums Register Login

Interesting TimeZone issue

+Pie Number of slices to send: Send
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!
+Pie Number of slices to send: Send
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 :| .
There's a way to do it better - find it. -Edison. A better tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1241 times.
Similar Threads
Date 01/01/1970 returning non-zero value for time
Calendar() / Date() bug ???
How to get the abbreviated timezone using java api ?
SimpleDateFormat.parse and SimpleDateFormat.format not producing identical values
TimeZone Usage
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:28:54.