[thelist] Java question: getTimezoneOffset() Deprecated
John C Bullas
jcbullas at nildram.co.uk
Tue Dec 30 03:10:01 CST 2003
Here is an example line of a clock program that a buddy recompiled after
some mods (not this line).
private static final int LOCALTIMEZONEOFFSET = (new
Date()).getTimezoneOffset();
I[using j2sdk1.4.2 and the line I got back from the compiler was shocking. ]
C:\Java\clock>javac Clock.java
Note: Clock.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
I don't know what it means :-)) but to me it falls in the same category as
exfoliated, SM and the rest of the lot...............
Okay, now to the serious bit of it all
This is what I've read in the API docs:
<http://java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html#getTimezoneOffset()>getTimezoneOffset()
Deprecated. As of JDK version 1.1, replaced by
-(Calendar.get(Calendar.ZONE_OFFSET) + Calendar.get(Calendar.DST_OFFSET)) /
(60 * 1000).
Well, that's easy peasy.
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?
FB
More information about the thelist
mailing list