Posts Tagged ‘Timezones and Java Dates’

Serialization, Timezones and Java Dates

Saturday, June 6th, 2009

Timezone has not been kept while transfering over http.

The data are stored in the tableModel on the client side. TableModel is serialized and sent over the http to the server. The servlet on the server deserializes the data into the tableModel. TableModel is stored into the database.

My client is located in the central Europe and the server is located in the USA. The client time was Jun 06 00:00:00 CEST 2009. The data was transferred over the http and the same date on the server was Jun 05 17:00:00 CDT 2009.

Solution:

I set GMT timezone on both sides.

TimeZone tz = TimeZone.getDefault();
tz.setDefault(TimeZone.getTimeZone(“GMT”));

The client and the server date time are the same after setting default timezone: Jun 06 00:00:00 GMT 2009.

 Do not hesistate to check out a hotel reservation software using the described technology.