Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calendar failed to get the days names in different languages than English

I'm trying to get the days of the week in German using the Calendar function getDisplayNames() with German locale.

Calendar now = Calendar.getInstance();
Map<String,Integer> displayNames = now.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, new Locale("de_DE"));

Instead I get the day of week names in English: Sunday, Monday, .... etc.
Am I doing something wrong or it simply doesn't work? Maybe it got somthing to do with the toString() of my IDEA debugger console? I'm using the latest Intellij 12.1.2.

like image 501
Snow Avatar asked Feb 17 '23 16:02

Snow


1 Answers

Use , Locale.GERMAN or use new Locale("de"), instead of new Locale("de_DE")

Map<String,Integer> displayNames = now.getDisplayNames(Calendar.DAY_OF_WEEK, 
            Calendar.LONG, Locale.GERMAN);

Map<String,Integer> displayNames = now.getDisplayNames(Calendar.DAY_OF_WEEK, 
            Calendar.LONG, new Locale("de"));

It is helpful to go through the Javadocs for Locale(String) constructor, which says "Construct a locale from a language code". The language code for German is "de" not "de_DE".

like image 176
AllTooSir Avatar answered Feb 19 '23 04:02

AllTooSir