tags:

views:

107

answers:

2

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.format(dateServerTimezone) + " "
    + serverTimezone.getDisplayName(locale);
A: 

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.

jowierun
I am using JDK 1.6, This problem is with Russian locale only for all timezones.For French, German etc Time Zone String converted to corresponding language.
coder
A: 

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));
}
ZloiAdun
thanks ZloiAdun
coder