Hi All,
Having a TimeZone object, is there any convenient way to get its String
represnatation in the MS Windows form of "GMT +- HH:MM" .
i.e. GMT - 08:00 for TimeZone.getTimeZone("America/Los_Angeles").
Thanks,
Asaf
Roland de Ruiter - 10 Aug 2006 13:39 GMT
> Hi All,
> Having a TimeZone object, is there any convenient way to get its String
[quoted text clipped - 3 lines]
> Thanks,
> Asaf
getRawOffset() returns the amount of milliseconds relative to UTC (which
I believe is (almost) the same as GMT). Some dividing by 1000 and 60 and
you could end up with the format you want.
<http://java.sun.com/j2se/1.5.0/docs/api/java/util/TimeZone.html#getRawOffset()>

Signature
Regards,
Roland
Thomas Weidenfeller - 10 Aug 2006 13:51 GMT
> Having a TimeZone object, is there any convenient way to get its String
> represnatation in the MS Windows form of "GMT +- HH:MM" .
> i.e. GMT - 08:00 for TimeZone.getTimeZone("America/Los_Angeles").
TimeZone tz = ...
off = tz.getOffset(new Date().getTime()); // considering DST
or
off = tz.rawOffset(); // ignoring DST
And some simple math to get the hour and minutes from the return value -
which is in milliseconds.
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
shakah - 10 Aug 2006 15:48 GMT
> Hi All,
> Having a TimeZone object, is there any convenient way to get its String
[quoted text clipped - 3 lines]
> Thanks,
> Asaf
You can get close to what you want with SimpleDateFormat (no colon,
though), with the benefit that it adjusts transparently for Daylight
Savings Time rules, e.g.:
jc@rs-dev2:/tmp$ cat tztest.java
public class tztest {
public static void main(String [] asArgs) {
java.text.DateFormat df = new java.text.SimpleDateFormat("'GMT 'Z")
;
for(int i=0; i<asArgs.length; ++i) {
java.util.TimeZone tz = java.util.TimeZone.getTimeZone(asArgs[i])
;
df.setTimeZone(tz) ;
System.out.println(asArgs[i] + " / " + tz.getDisplayName() + ": "
+ df.format(new java.util.Date())) ;
}
}
}
jcx@rs-dev2:/tmp$ java -classpath "." tztest America/New_York UTC
America/Los_Angeles
America/New_York / Eastern Standard Time: GMT -0400
UTC / Coordinated Universal Time: GMT +0000
America/Los_Angeles / Pacific Standard Time: GMT -0700