I'm working with some quite old code, which makes the assumption that "TimeZone.getDefault()" returns an instance of java.util.SimpleTimeZone. That may have been true for some JVMs (e.g. the old Apple MRJ), but it's not true now on OS X. And according to the javadocs, one shouldn't make assumptions about the class returned by getDefault(). (The class it returns is in the sun.* hierarchy, which I can't use since this is an applet.)
The reason it matters is because the code does some advanced calculations with timezones, daylight savings time and the like, and it uses the SimpleTimeZone.getRawOffset method. And I can't seem to create an instance of SimpleTimeZone directly, because for that one needs the raw offset to begin with.
Now, I know that the timezone is the one where the user is located, so how do I do construct a local SimpleTimeZone? Or, which seems to amount to the same thing, how do I calculate the local raw offset?
Thanks in advance for any clues.
Ping & DNS - updated with new look and Ping home screen widget
Isn't getRawOffset() defined as an abstract method in TimeZone? You should be able to access this for any TimeZone, not just SimpleTimeZone. You may also benefit from useDaylightTime() and getDSTSavings() - or just use getOffset(). Unfortunately there isn't really an easy way to learn the start and end dates for DST from a TimeZone, so if you need that, you might need to go to a trial-and-error approach. Note that this can vary from year to year.
"I'm not back." - Bill Harding, Twister
Joined: Mar 22, 2005
Drat. You're right. I could have sworn that I tried that first, and that the compiler complained about it. Works fine now - thanks.
Joined: Mar 22, 2005
If you were wondering what this was about, I noticed that no functioning copies of Martin Minow's SunSphere applet still seemed to be out there. So I reactivated it here.
It was prompted by some other thread mentioning that the earth rotates "faster" around the equator than it does near the poles. [ July 26, 2007: Message edited by: Ulf Dittmer ]