Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Translate Timezone name using Timezone JAVA API

Vikash_kumar_18
Level 1
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
Umesh_Thakur
Correct answer by
Community Advisor
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
kishorekumar14
Level 7
Level 7

Hi @Vikash_kumar_18 ,

 

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

Umesh_Thakur
Correct answer by
Community Advisor
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