开发者

Problem in TimeZone display in java while using Russian locale

开发者 https://www.devze.com 2023-01-10 18:13 出处:网络
I am facing a problem while using Russian locale, Time Zone part of the date is not converting to Russian.

I am facing a problem while using Russian locale, Time Zone part of the date is not converting to Russian. i.e. if "Aug 10, 2010 4:02:09 PM Yakutsk Time" is the time, it is converting to - With Russian locale - "10.08.2010 16:02:09 Yakutsk Time 10" With French Locale - "août 2010 16:02:09 Heure du Iakoutsk"

I am using following code (Russian locale is supported on my server)

     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.开发者_如何学Cformat(dateServerTimezone) + " "
    + serverTimezone.getDisplayName(locale);


Time Zone names are obtained by Java from the sun.util.resources.TimeZoneNamesBundle. There is a TimeZoneNames base resource class and there are localizations (see in 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  

So only the above languages have the localized Time Zone names. The following test confirms that most of the locales do not have localized time zone names:

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


Java has it's own built in timezones definitions. Assuming your timezone is aok on your server, then perhaps the problem lies in the Java definitions. Lookup tzupdater to see if you need to either find a newer version of the timezones, or build your own. If you are using an old JVM, try grabbing the latest version to see if your timezone is supported.

0

精彩评论

暂无评论...
验证码 换一张
取 消