[thelist] Java question: getTimezoneOffset() Deprecated

Ben Gustafson Ben_Gustafson at lionbridge.com
Tue Dec 30 09:12:51 CST 2003


> Date: Tue, 30 Dec 2003 09:10:01 +0000
> From: John C Bullas <jcbullas at nildram.co.uk>
> To: thelist at lists.evolt.org <thelist at lists.evolt.org>
> Subject: [thelist] Java question: getTimezoneOffset() Deprecated

<snip>

> Now the line of code looks like this:
> private static final int LOCALTIMEZONEOFFSET = 
> (Calendar.get(Calendar.ZONE_OFFSET) + 
> Calendar.get(Calendar.DST_OFFSET)) / 
> (60*1000);
> 
> But that actually does not compile. The error message is now:
> Clock.java:260: non-static method get(int) cannot be 
> referenced from a 
> static context
>      private static final int LOCALTIMEZONEOFFSET = 
> (Calendar.get(Calendar.ZONE_OFFSET) + 
> Calendar.get(Calendar.DST_OFFSET)) / 
> (60*1000);                                         ^
> 
> Why is this not a straight replacement?
> 
> Can you please put me in the right direction?

Hi John,

What the error message means is that you need to first instantiate an
instance of the Calendar object, i.e.:

	Calendar cal = new Calendar();

This will create a Calendar object with the default time zone and
locale. To get the time zone offset, call the get() method by using the
Calendar object to access it and pass the static constant value for
ZONE_OFFSET to it, like:

	int zoneOffset = cal.get(Calendar.ZONE_OFFSET);

This will return the "raw offset from GMT in milliseconds" (according to
the API doc at
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html#ZONE_OFF
SET .

Hope this helps!

--Ben


More information about the thelist mailing list