Java默认语言环境回退

时间:2013-06-27 09:51:56

标签: java internationalization globalization

在Java中,我使用Language和Country参数创建Locale 然后使用适当的日期格式。

但是,Java不支持所有Language_Country组合和后备到默认语言环境格式(在我的情况下为en_US)。

有没有办法确定是否发生了后备?

E.g:

当我使用Locale locale = new Locale("xx","xx");

创建区域设置时

然后

((SimpleDateFormat)DateFormat.getDateInstance(DateFormat.SHORT,locale)).toLocalizedPattern();

返回M/d/yy,以便它回退到en_US。

所以我需要像

这样的东西

locale.isDefault

2 个答案:

答案 0 :(得分:1)

您可以检查区域设置是the available locales之一:

Set<Locale> locales = new HashSet<>();
Collections.addAll(locales, Locale.getAvailableLocales());

Locale locale = new Locale("xx", "xx");
System.out.println(locales.contains(locale)); //prints false

locale = new Locale("fr", "FR");
System.out.println(locales.contains(locale)); //prints true

答案 1 :(得分:0)

Locale.getDefault()。等于(区域)

相关问题