2010-08-10 76 views
2

我在使用俄語語言環境時遇到問題,時區部分日期未轉換爲俄語。 即如果「2010年8月10日4時02分09秒雅庫茨克時間」是時間, 它將轉換爲 - 與俄語語言環境 - 「10.08.2010 16:02:09雅庫茨克時間10」 與法語語言環境 - 「AOUT 2010 16時02分09秒HEURE杜Iakoutsk」在使用俄語語言環境的java中顯示TimeZone問題

我使用下面的代碼(俄羅斯語言環境支持我的服務器上)

 SimpleDateFormat formatterWithoutTimezone = new SimpleDateFormat(
    "dd-MMM-yyyy HH:mm:ss"); 

    SimpleDateFormat formatterServerTimezone = new SimpleDateFormat(
    "dd-MMM-yyyy HH:mm:ss zzz"); 
    TimeZone serverTimezone = TimeZone.getDefault(); 
    formatterServerTimezone.setTimeZone(serverTimezone); 
    String dateSrcStr = formatterWithoutTimezone.format(dateSrc) + " UTC"; 
    Date dateServerTimezone = formatterServerTimezone.parse(dateSrcStr); 
    DateFormat displayFormatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale); 
    String formatedDate = displayFormatter.format(dateServerTimezone) + " " 
    + serverTimezone.getDisplayName(locale); 

回答

3

時區名稱由Java從sun.util.resources.TimeZoneNamesBundle獲取。有一個TimeZoneNames基礎資源類和有本地化(見rt.jar中):

TimeZoneNames_de.class 
TimeZoneNames_en.class 
TimeZoneNames_en_CA.class 
TimeZoneNames_en_GB.class 
TimeZoneNames_en_IE.class 
TimeZoneNames_es.class 
TimeZoneNames_fr.class 
TimeZoneNames_it.class 
TimeZoneNames_sv.class 

因此,只有上面的語言有本地化的時區名稱。以下測試證實大多數語言環境沒有本地時區名稱:

TimeZone timeZone = TimeZone.getTimeZone("Asia/Yakutsk"); 
for (Locale locale : Locale.getAvailableLocales()) { 
    System.out.println(locale.getDisplayName() + timeZone.getDisplayName(locale)); 
} 
0

Java有它自己的建在區定義。假設你的時區在你的服務器上是aok,那麼問題可能在於Java定義。查找tzupdater以查看是否需要查找更新版本的時區或建立自己的時區。如果您使用的是舊JVM,請嘗試抓取最新版本以查看您的時區是否受支持。

+0

我正在使用JDK 1.6,此問題僅適用於所有時區的俄語區域設置。 法語,德語等時區字符串轉換爲相應的語言。 – dadua 2010-08-10 07:21:14

相關問題