Friday, June 6, 2014

Re: GWT 2.4 timezone issue

Date object does not have a time zone information. You see a time zone when you print/display the date object, and the machine is using its own time zone by default.

I save all dates in the datastore as Long values: date.getTime(). When I need to display a date in a browser, I pass the GWT TimeZone object. For example,


private static DateTimeFormat format = DateTimeFormat.getFormat(PredefinedFormat.DATE_MEDIUM);

public void setDate(Long date, TimeZone timeZone) {
    setValue(date == null ? null : format.format(new Date(date), timeZone));
}

You can read more about GWT TimeZone here:

http://www.gwtproject.org/javadoc/latest/com/google/gwt/i18n/client/TimeZone.html

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment