format dates in specific timezone

760 views
Skip to first unread message

mariyan nenchev

unread,
Aug 25, 2011, 8:52:08 AM8/25/11
to Google Web Toolkit
Hi,

How can i format dates in gwt for specific time zone like "GMT+2" for example.

Regards.

Ashwin Desikan

unread,
Aug 25, 2011, 9:01:53 AM8/25/11
to google-we...@googlegroups.com
You can use the DateTimeFormat function defined in the  com.google.gwt.i18n.client.DateTimeFormat to specify the format.

check out the http://gwt.google.com/samples/Showcase/Showcase.html#!CwDateTimeFormat example in showcase on how to set the various formats

regards
Ashwin
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

mariyan nenchev

unread,
Aug 25, 2011, 9:27:26 AM8/25/11
to google-we...@googlegroups.com
I don't need to change the format, i want to format the date according to timezone.

DateTimeFormat has method format with args date and timezone, but i don't know how to pass GMT like time zone for example GMT+1, GMT+0, GMT-2 etc...

This is throwing exception that GMT+1 is unknown. This is because createTimeZone method is receiving strings from TimeZoneConstants and i can't use them.


Regards.


 DateTimeFormat.getShortDateFormat().format(new Date(System.currentTimeMillis()), TimeZone.createTimeZone("GMT+1"))

Sydney

unread,
Aug 25, 2011, 4:02:01 PM8/25/11
to google-we...@googlegroups.com
TimeZone.createTimeZone(TimeZoneInfo.buildTimeZoneData(TimeZoneConstants.europeParis()));
Not tested

Sydney

unread,
Aug 25, 2011, 4:05:23 PM8/25/11
to google-we...@googlegroups.com
If you want to use GMT+1 timezone style I guess you need to do some kind of mapping.

mariyan nenchev

unread,
Aug 26, 2011, 5:48:57 AM8/26/11
to google-we...@googlegroups.com
I don't want to make mappings manually. 

It's very funny that such thing can't be done with gwt.

On Thu, Aug 25, 2011 at 11:05 PM, Sydney <sydney....@gmail.com> wrote:
If you want to use GMT+1 timezone style I guess you need to do some kind of mapping.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

Palo G.

unread,
Sep 20, 2011, 10:35:22 AM9/20/11
to Google Web Toolkit
Hi, I found this discussion after hours of thinking and googling same
problem. We have simple problem that turned out to be a huge problem
in GWT. There is no tool that can get client time zone and return that
bloody TimeZoneInfo instance.

So I have to ask if you had found some solution or how did you end up?

thanks

Stevko

unread,
Sep 22, 2011, 5:22:58 PM9/22/11
to Google Web Toolkit
I've been doing the same research deep dive and came up with this
nugget of code

final TimeZoneConstants timeZoneConstants =
GWT.create(TimeZoneConstants.class);
TimeZone usPacific = TimeZone.createTimeZone(

TimeZoneInfo.buildTimeZoneData(timeZoneConstants.americaLosAngeles()));
Date dt = new Date(2007 - 1900, 7 - 1, 1);
assertTrue(usPacific.isDaylightTime(dt));
assertEquals("PDT", usPacific.getShortName(dt));
assertEquals("Pacific Daylight Time", usPacific.getLongName(dt));

from http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/test/com/google/gwt/i18n/client/TimeZoneTest.java?r=3655
Reply all
Reply to author
Forward
0 new messages