DateBox and TimeZone

849 views
Skip to first unread message

Eric

unread,
Jun 24, 2011, 7:44:31 AM6/24/11
to Google Web Toolkit
Hello All,

How can I force a GWT DateBox to choose dates in a particular time
zone? Users off this application might be in many time zones, but,
for this purpose, any date entered should be in "America/Denver".
Since one of the people who enter this information works in eastern
time the dates he enters appear a day before the date he enters. I've
searched this list and googled in general, but I can't find how to
override the default time zone for a DateBox.

Code:

Some constants universally available:

public static final TimeZoneConstants timeZoneConstants =
GWT.create(TimeZoneConstants.class);
public static final TimeZone usMountain =
TimeZone.createTimeZone(timeZoneConstants
.americaDenver());
public static final DateTimeFormat dateDtf =
DateTimeFormat.getFormat("MM/dd/yyyy");


Code that displays the date:
String displayDate = Constants.dateDtf.format(d, usMountain)

The DateBox where the date is entered:
DateBox.DefaultFormat pickerFormat = new
DateBox.DefaultFormat(Constants.dateDtf);
DateBox myDb = new DateBox(new DatePicker(), null, pickerFormat);

There are many places I could expect to be able to set the Time Zone:
on the DateTimeFormat, on the DateBox.DefaultFormat, on the DateBox,
in DateBox.getCalendarModel() . . . Any I blind? I can't see the
method anywhere.

Thanks,
Eric


Eric

unread,
Jun 28, 2011, 10:05:56 PM6/28/11
to Google Web Toolkit
So apparently no one know and/or no one cares ;)

Or this post just slipped through the cracks.

I ended up solving my problem with date arithmetic on the server side,
but I'm still curious if this is possible.

Thanks,
Eric

Ashwin Desikan

unread,
Jun 29, 2011, 12:09:58 AM6/29/11
to Google Web Toolkit
Eric,

I had a similar requirement for one of my projects, so i did the
following. I used the following format to part date/ time in my
DateBox

DateTimeFormat.getFormat("MMM dd yyyy H:mm")

Now, with the above format, the local timezone is automatically picked
up by the DatePicker. But since DatePicker does not allow you to
select time, the time defaults to 00:00:00. I placed a drop list in my
view where the user could choose the time. On value change on the drop
list, update the date retunred by the datebox by replacing the time
with the one picked from list box.

Regards
Ashwin

bharath.m...@gmail.com

unread,
Jul 1, 2015, 6:09:36 AM7/1/15
to google-we...@googlegroups.com
Hi Eric,

Even i am having the same issue. i want timezone to be set to "america/los_angeles". how did you resolve it using airthmetic could you please explain.
I tried the following scenario.
created new Date() in java code so it will take server timezone i.e "america/los_angeles" n tried setting the startdate from front end which user entered. it works when "america/los_angeles" date is same as "asia/kolkata" but gives one day back when date is different like "asia/kolkata" 01/07/2015 10:00:00 am IST and "america/los_angeles" is "30/06/2015 9:30:00 pm PDT"
Reply all
Reply to author
Forward
0 new messages