views:

77

answers:

2

Will TimeZone.getAvailableIDs(); get the same number of timezones regardless of what locale I'm running in?

+2  A: 

Yes.

TimeZone.getAvailableIDs() returns all known time zones and has nothing to do with locale.

I am interested in why you thought it was possible that it could be different based on locale.

As Gunslinger47 points out, time zones do occasionally change and you need to either update to a new JDK/JRE or patch the old one, but again this is independent of locale.

hbunny
Not to say that Lance should hardcore the value. The number of timezones in existence changes all the time, as recently as March 2010.
Gunslinger47
But time zone rules are independent of locales, which is why I've edited my answer to ask why he thought it could be different.
hbunny
I'm just not very experienced with Java, and I /think/ I've just finished watching Locale.getAvailableLocales() hand back a different number of locales based on the device (I'm writing Android code). I didn't think TimeZone.getAvailableIDs() would return different timezones based on.. well.. anything... but I just wanted to make sure, and I knew someone more experienced in Java would be able to answer more confidently than I could.
lance
A: 

If you have computers running in different timezones that are running the exact same Java version, then TimeZone.getAvailableIDs(); will return the same result on those computers.

However, the list can (and does) change between different Java versions (even between different update versions).

Why are you asking this question; what's the underlying problem you're trying to solve with the answer to your question? I think it's not a good idea to write a program that has expectations about what the result of TimeZone.getAvailableIDs(); looks like, since the Java API does not make any promises with regard to this.

Jesper
I was up against a need to map Java's timezones to a list of a subset supported by a third-party system. I'm no longer up against that problem, but this question came to mind in the meantime.
lance