PDA

View Full Version : HttpInvoker and Dates timezone issue



jamin
May 16th, 2007, 07:00 AM
Hi,

I have two machines setup. the machines are identical, same hardware, jvm, tomcat and os. The first machine runs a web application that gets data from another web application running on the second machine. The web apps use springs HttpInvoker mechanism.

What I have noticed is that any dates transferred between the web apps have a different timezone. They start off in BST on the seconds machine and then end up in GMT on the first machine.

If i type date in the shell of both machines they both report the time in BST.

Any one got any ideas?

Andreas Senft
May 16th, 2007, 07:11 AM
Do you refer to java.util.Date instances? Just wondering, because Date does not have timezone information. Could you provide more details?

Regards,
Andreas

jamin
May 16th, 2007, 07:24 AM
Yes i mean java.util.Date instances. Im connected to both webapps via a debugger which uses the dates toString() method to show the dates.

Andreas Senft
May 16th, 2007, 07:48 AM
I would not rely on Date.toString(). Important is, that Date.getTime() yields the same value for both Date instances. Is that the case?

jamin
May 16th, 2007, 08:00 AM
Yes the both report the same value. So i guess its down to the way im displaying them in the html interface to web app 1

Andreas Senft
May 16th, 2007, 08:10 AM
Yes the both report the same value. So i guess its down to the way im displaying them in the html interface to web app 1

Yes, I think so. If you really need timezone information I would use Calendar instead (or some class of a more usable date library). If it's just about displaying I would use an appropriate DateFormat.

Regards,
Andreas

jamin
May 16th, 2007, 08:24 AM
From the Date class..

/**
* Save the state of this object to a stream (i.e., serialize it).
*
* @serialData The value returned by <code>getTime()</code>
* is emitted (long). This represents the offset from
* January 1, 1970, 00:00:00 GMT in milliseconds.
*/
private void writeObject(ObjectOutputStream s)
throws IOException
{
s.writeLong(getTimeImpl());
}

This explains the change in zone.