1

I have to format date/time in my gwt app with specific timezone, which is loaded from the server. Possible timezones are like this GMT, GMT+1, GMT-2 etc... Up to now i used DateTimeFormat to format my timestamps, and they used client's locale.

PLease help.

user358448
  • 1,127
  • 3
  • 20
  • 39

1 Answers1

3

You can format in any timezone you want with DateTimeFormat, you just have to pass it as the second argument to the format method. And to obtain a TimeZone object, depending on how you want to present the timezone information (if ever) in the formatted date/time, you can use either createTimeZone(int) or createTimeZone(String) (getting the string out of TimeZoneConstants).

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Thanks, Thomas. But the timezone is retrieved from the server in format GMT+/-1,2,3 etc.. So i can't user TimeZoneConstants. I can extract +/-{digit} from the string (for example "GMT+1") and pass it to createTimeZone(int), but i read that this returns different timezone depending in which time zone is the browser (is that true?). – user358448 Aug 26 '11 at 14:58
  • Er, where did you read that? A timezone offset the distance from UTC, the user's current timezone doesn't matter. – Thomas Broyer Aug 26 '11 at 15:15
  • So, if the loaded server timezone is for example 'GMT-2' i can do the following: String serverTimeZone = "GMT-2"; int tz = Integer.parseInt(serverTimeZone.substring(3));// returns -2 TimeZone timezone = TimeZone.createTimeZone(tz*60); // this gives me server time zone for GMT-2 //use it to format date/time in GMT-2 time zone – user358448 Aug 29 '11 at 09:45