我正在尝试使用具有德语语言环境的日历函数 getDisplayNames() 获取德语的星期几。
Calendar now = Calendar.getInstance();
Map<String,Integer> displayNames = now.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, new Locale("de_DE"));
相反,我得到英文星期几的名称:Sunday、Monday,....等
我是做错了什么还是根本不起作用?
也许它与我的 IDEA 调试器控制台的 toString() 有关?我使用的是最新的 Intellij 12.1.2。
最佳答案
使用 , Locale.GERMAN
或使用 new Locale("de")
而不是 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"));
浏览 Locale(String) 的 Javadocs 很有帮助构造函数,它表示“从语言代码构造语言环境”。德语的语言代码是 "de" 而不是 "de_DE"。
关于java - 日历无法获取非英语语言的日期名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16313372/