Expand my Community achievements bar.

SOLVED

Translate Timezone name using Timezone JAVA API

Avatar

Level 1
import java.util.*;
public class HelloWorld{

     public static void main(String []args){
        Locale locale = new Locale("zh","CN");
        TimeZone zone = TimeZone.getTimeZone("America/Chicago");
        String displayNameShort = zone.getDisplayName(true, TimeZone.SHORT, locale);
        System.out.println("Short time zone name - " + displayNameShort);
        String displayNameLong = zone.getDisplayName(true, TimeZone.LONG, locale);
        System.out.println("Long time zone name - " + displayNameLong);
     }
}

Output - 
Short time zone name - CDT // Not translated
Long time zone name - 中央夏令时 // Translated


I am able to translate the full display name of the timezone but am not able to translate the abbreviation form of timezone.
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Vikash_kumar_18,

Here TimeZone.SHORT is doing the magic that you are getting, since TimeZone.SHORT is designed to provide you the abbreviation for the time zone so you are getting the abbreviated text without translation but if you use TimeZone.LONG you will be getting a long word representing the time zone so you are getting that long word translated in the local language.

for example TimeZone.SHORT will give you the PST and TimeZone.LONG will return "Pacific Standard Time.".

If you need abbreviation also to be converted in locale text then you will have to use some other API to convert that text to chinese.

 

Hope this will help.

Umesh Thakur

 

View solution in original post

2 Replies

Avatar

Community Advisor

Hi @Vikash_kumar_18 ,

 

I guess this question is not related to AEM but Java.

Avatar

Correct answer by
Community Advisor

Hi @Vikash_kumar_18,

Here TimeZone.SHORT is doing the magic that you are getting, since TimeZone.SHORT is designed to provide you the abbreviation for the time zone so you are getting the abbreviated text without translation but if you use TimeZone.LONG you will be getting a long word representing the time zone so you are getting that long word translated in the local language.

for example TimeZone.SHORT will give you the PST and TimeZone.LONG will return "Pacific Standard Time.".

If you need abbreviation also to be converted in locale text then you will have to use some other API to convert that text to chinese.

 

Hope this will help.

Umesh Thakur