views:

141

answers:

1

The code below outputs "Japan Standard Time".

TimeZone tz = TimeZone.getTimeZone("Asia/Tokyo");
Locale locale = new Locale("ja_JP");
System.out.println(tz.getDisplayName(locale));

I am expecting it to output something with Kanji along the lines of "日本標準時". It does not seem to matter what timezone ID or locale I pass to getDisplayName()--the resulting text is always English. How do I get the localized values?

I am using Sun Java SDK/JRE version 1.6.0_18. I also tried running the tzupdater utility but got no change in results.

+3  A: 

It works if you use the predefined JAPAN locale:

System.out.println(tz.getDisplayName(Locale.JAPAN));

At least, it print a bunch of questions marks on my console, rather than "Japan Standard Time", which has to be a good sign.

Locale.JAPAN is defined as new Locale("ja_JP_", "ja", "JP"), so there's clearly some subtlety here in the constructor arguments.

skaffman
ISO language and country codes are not always consistent. While "JP" is the country code for Japan (country codes are usually written in upper case), the language code for Japanese is "ja" (language codes are usually written in lower case).
jarnbjo
Isn't it high time to configure your IDE console to output UTF-8? ;)
BalusC
Thank you, both. Skaffman clued me into the problem being the locale. If I create a new locale like `new Locale("ja", "JP");` it will also work.
Erik Hermansen