Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

java.util.TimeZone String representation

Thread view: 
asaf - 10 Aug 2006 13:00 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.