基本上,正如标题所述,我已经尝试过:
Locale currentLocale = Locale.getDefault();
System.out.println(currentLocale.getDisplayLanguage());
System.out.println(currentLocale.getDisplayCountry());
System.out.println(currentLocale.getLanguage());
System.out.println(currentLocale.getCountry());
System.out.println(System.getProperty("user.country"));
System.out.println(System.getProperty("user.language"));当我在寡妇的环境中设置了完全不同的东西时,这一切都给了我美国或英语。请给我任何建议。因此,我希望得到“国家代码”,例如,如果我在系统中设置了波兰,我希望"PL“,但我得到”美国“
发布于 2020-10-07 16:15:12
默认的Java区域设置与系统区域设置不一样,因为它可以被重写
具有Locale.setDefault().、user.language和user.variant系统属性的
有非标准的、无文档的API来获取操作系统提供的地区信息。它是在Windows或更高版本上实现的。试试下面的片段。
import sun.util.locale.provider.HostLocaleProviderAdapter;
...
static String getHostCountry() {
for (Locale locale : new HostLocaleProviderAdapter().getAvailableLocales()) {
if (!locale.getCountry().isEmpty()) {
return locale.getCountry();
}
}
return null;
}https://stackoverflow.com/questions/64243363
复制相似问题