How do I get GWT DateTimeFormat to display using the server TimeZone, rather than the client's?
Solution 1
The "easiest" solution (one that doesn't require any communication with the server) is just forcing DateTimeFormat
to use a particular timezone (the one your server is in), like this:
String pseudoServerTime = DateTimeFormat.getFullTimeFormat().format(new Date(), TimeZone.createTimeZone(TimeZoneConstants.europeWarsaw());
You can hardcode the timezone string/object somewhere as public static final
so that it can be easily changed, if you move/change servers (and the GWT compiler will inline this, so no performance penalty).
Solution 2
Will the date be modified on the client? If not do the format on the server and just send over a string value. One last thing. There seems to be some issues with Dates on the client side in GWT. Refer to http://blog.gerardin.info/archives/674
Comments
-
RodeoClown almost 2 years
I am trying to display a (java.util.)Date client-side, and it keeps using the browser's timezone, resulting in a different date visible depending on where you view the page.
How do I get the Formatter (DateTimeFormat) to display the date using the server's timezone rather than the user?
Thanks