Client side time zone support in GWT

4,807 views
Skip to first unread message

Joakim

unread,
Nov 5, 2009, 9:33:06 AM11/5/09
to Google Web Toolkit
Hi everyone!

I'm working on an app where I need to support the following scenario:
The server is located in time zone A
The client's browser is set to time zone B
The app is configured to display date/time in time zone C

Since gwt does not support Calendar and the native support for time
zones in javascript is non-existent I can't think of a nice and clean
solution to this problem.

Have any of you done something similar or do you know of any good
utils I could use?

Thanks,
Joakim

lowecg2004

unread,
Nov 6, 2009, 5:18:12 AM11/6/09
to Google Web Toolkit
Hi Joakim,

Take a look at the DataTimeFormat object. I use the following to
determine the client's timezone:

/**
* Get the client's time zone in the format "GMT[+-]hh:mm"
* @return
*/
public static String getTimeZone() {
final Date now = new Date();

final String timezone = DateTimeFormat.getFormat("zzzz").format
(now);

Log.info("Client timezone = " + timezone);

return timezone;
}

Cheers,

Chris.

Yozons Support on Gmail

unread,
Nov 6, 2009, 12:13:39 PM11/6/09
to google-we...@googlegroups.com
Take a look at the DataTimeFormat object.  I use the following to
determine the client's timezone:

       /**
        * Get the client's time zone in the format "GMT[+-]hh:mm"
        * @return
       */
       public static String getTimeZone() {
               final Date now = new Date();

               final String timezone = DateTimeFormat.getFormat("zzzz").format
(now);

               Log.info("Client timezone = " + timezone);

               return timezone;
       }

Unfortunately, it uses a user-unfriendly "GMT+-hh:mm" format for timezone rather than the names most people are familiar with, such as in the US mainland we have EST, CST, MST and PST.  Few here think in terms of offset from GMT.  And somehow the Date.toString() method has the nicer name I've noticed, but the DateTimeFormat seems to not want to give it back even with just 'z' or 'zzz'.

lowecg2004

unread,
Nov 7, 2009, 6:55:03 AM11/7/09
to Google Web Toolkit
Re: user unfriendliness of timezone format

Agreed. I was using this to report a timezone back to the server
where I was matching it to one of the defined timezones in Java which
has had mixed success.

I'll investigate more on the Data.toString(), do you happen to know if
the functionality is legitimate GWT client code that is consistent
between browsers? Sometimes with date objects they will work in
debug mode (you just get the regular Java version) but not in final
compiled code.

There is more information on dates here:

http://code.google.com/p/gwt-examples/wiki/gwtDateTime

Generally I've the area of client site timezones a bit of a pig to
work with, has anyone got any tips/links for working with timezones?

Cheers,

Chris.

Yozons Support on Gmail

unread,
Nov 9, 2009, 8:41:54 PM11/9/09
to google-we...@googlegroups.com
You are right...the pretty timezone was when in debug mode.

When I tested on IE and Firefox, it was the ugly GMT-800 look.  RRRR....

It's a shame because I have the timezone string to use in the server.  I can give this to the client, but I can't find any way for the client to put it to use.

I have taken to returning String instead of Date for all dates that don't need to be sorted by client widgets, but those that do still suffer this ugly bit of display.


Reply all
Reply to author
Forward
0 new messages