java默认情况下DecimalFormat和DateFormat使用什么语言环境?(为什么它与Locale.getDefault()不同?)
调试我的应用程序时,如果发现DecimalFormat
和DateFormat
默认设置为使用nl_NL
,但系统区域设置似乎是en_US
我通过评估发现了第一个:
new DecimalFormat().symbols.locale
new SimpleDateFormat().locale
第二点:
Locale.getDefault()
System.getProperty("user.country")
System.getProperty("user.language")
那里发生了什么
默认情况下,如何将这些格式化程序设置为使用特定的语言环境?(我正在编写单元测试,希望在不接触应用程序代码的情况下设置特定的区域设置)
# 1 楼答案
从Java7开始,the default locale comes in two categories:“显示”和“格式”。 两者最初都是根据环境设置的。可以通过调用
Locale.getDefault(Category)
找到它们除了问题中提到的系统属性外:
运行JVM时,还可能出现以下情况:
原因似乎是some OS's allow independent localization settings for displaying text and for formatting dates, numbers and currency
回答我的最后一个问题,打电话给
Locale.setDefault(Locale)
the default locale will be set for all categories