Question

I send timestamps to my GWT client using GMT/Zulu time, with each string designated as such (ie. 2012-01-19T16:29:18Z, or 4:29pm GMT). How do I show this in the browser in the local timezone? So for me in CST I expect to see 10:29am.

If I do no formatting I get the date as 4:29pm, which I expect, If I use a TimeZone object of TimeZone.createTimeZone(0), I get for some reason 10:29PM (not AM as expected). I suppose I'm supposed to pass in something more meaningful than 0, but how do I obtain the right value for the where the browser is running?

J

Was it helpful?

Solution

You can get the time-zone offset that is configured in the browser using:

Date d = new Date();
d.getTimezoneOffset();

It won't give you the timezone name, I don't think that's possible to get.

Do you send the time as a timestamp, or string? I find the best approach is to send UTC timestamps to the client and then format them to whatever zone I need using DateTimeFormat/TimeZone. But I guess that if you are parsing the date string including the offset, you end up with a UTC timestamp anyway.

OTHER TIPS

If you want the GWT client code to format the time in the browser time zone, you should pass the data from the server to the client as a java.util.Date object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top