• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.util.TimeZone question

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic