aspose file tools*
The moose likes Java in General and the fly likes java.util.TimeZone question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.util.TimeZone question" Watch "java.util.TimeZone question" New topic
Author

java.util.TimeZone question

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41472
    
  51
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 - my free Android networking tools app
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41472
    
  51
Drat. You're right. I could have sworn that I tried that first, and that the compiler complained about it. Works fine now - thanks.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41472
    
  51
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.util.TimeZone question