I'm using GWT RPC to send a string containing a date from the client to the server (it has to be this way, because it's on a request header).
On the server side I parse that string with SimpleDateFormat and make the logic I want.
I'm setting both my cell phone and computer to different time zones, and will use hosted mode and running the test project on tom cat.
Here's the code:
Client:
DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss Z");
Date date = new Date();
System.out.println("client: " + date.toString());
System.out.println("client: " + dtf.format(date));
builder.setHeader("Date1", dtf.format(date));
Server:
String dateHeader = request.getHeader("Date1");
System.out.println("Server date header from client: " + dateHeader);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
System.out.println("x = " + sdf.parse(dateHeader));
System.out.println("Timezone = " + df.getTimeZone().getDisplayName());
Result:
Hosted Mode
client: Wed Apr 11 17:29:49 NOVST 2012
client: 2012-04-11 17:29:49 +0700
Server date header from client: 2012-04-11 17:29:49 +0700
x = Wed Apr 11 17:29:49 NOVST 2012
TomCat
- Using PC: Client, and server have the same time.
(Can't see the print of the client, obviously)
Server date header from client: 2012-04-11 17:31:37 +0700
x = Wed Apr 11 17:31:37 NOVST 2012
- Cellphone client, has a different from the server.
Server date header from client: 2012-04-11 15:34:35 +0500
x = Wed Apr 11 17:34:35 NOVST 2012
Conclusion: SimpleDateFormat ignores the Timezone that comes on the string. I don't want that! I want this to work properly. How can I make this work? Thank you in advanced.