I use GWT RPC to send a string containing the date from the client to the server (this should be so because it is in the request header).
On the server side, I parse this line with SimpleDateFormat and do the logic that I want.
I install both my mobile phone and computer in different time zones, and will use the placement mode and launch a test project on tom cat.
Here is the code:
Customer:
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:
Hosting
client: Wed 11 Apr 17:29:49 NOVST 2012
client: 2012-04-11 17:29:49 +0700
Title server date from the client: 2012-04-11 17:29:49 +0700
x = Wed Apr 11 17:29:49 NOVST 2012
Tomcat
- PC usage: client and server have the same time.
( , )
: 2012-04-11 17:31:37 +0700
x = 11 17:31:37 NOVST 2012
: 2012-04-11 15:34:35 +0500
x = 11 17:34:35 NOVST 2012
:
SimpleDateFormat , . ! , . ? .