Mac OS X中的什么设置影响Java中的“区域设置”和“日历”? [英] What settings in Mac OS X affect the `Locale` and `Calendar` inside Java?
问题描述
这两个问题促使我想知道Mac OS X中的哪些设置会影响区域设置和日历 Java中的默认值和行为:
在日历中键入以下两个属性:
这两个值的默认值为 1
在Java 7& 8当在默认美国上运行时。
我已经看到一些特殊的行为,如何影响java的这些属性。 util.Calendar。
结论
确定的事实:
- Java
Locale
由系统偏好设定中的语言决定。 - 日历的两个属性不受通过Mac的语言更改的Java区域设置的影响。
- 很奇怪,可能是一个错误,手动选择每周的第一天 >系统首选项中的弹出菜单无法影响Java中的等效属性。影响Mac设置作为选择区域的一部分会影响Java,但手动选择弹出菜单不会。
- 通过Mac设置Java区域设置 会影响其属性(一个明显的矛盾)。
$ b
详细
运行此代码作为测试。
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
public class TestCalendar
{
public static void main(String [] args)
{
Locale locale = Locale.getDefault );
Calendar c = Calendar.getInstance();
c.setTime(new Date(new Long(1293840000000l))); //年的第一个时刻2011年在UTC。
System.out.println(Locale:+ locale +| FirstDayOfWeek:+ c.getFirstDayOfWeek()+| MinimialDaysInFirstWeek:+ c.getMinimalDaysInFirstWeek());
}
}
使用Mac OS X 10.8.5在安装操作系统期间选择的具有美国
区域设置的具有Java 8 Update 11的Mac OS X(Mavericks)上托管的Parallels 9虚拟机中,我使用系统偏好
> 语言&文本
。
系统偏好设置>语言&文本>地区>一周的第一天
奇怪的是,在地区选项卡没有效果。 Java报告 FirstDayOfWeek:1
是否将该弹出式菜单设置为星期日或星期一。
地区:en_US | FirstDayOfWeek:1 | MinimialDaysInFirstWeek:1
重新启动NetBeans IDE无济于事。重新启动Mac(虚拟机)没有帮助。
系统偏好设定>语言&文字>区域
在区域标签上,勾选[显示所有区域]核取方块以查看更多区域。选择法语
> 法国
。立即运行IDE。无需重新启动IDE或操作系统,也无需关闭系统首选项窗口。
语言环境:en_US | FirstDayOfWeek:2 | MinimialDaysInFirstWeek:4
对两个帐户感兴趣。
- 现在我们知道区域设置会影响这两个键日历设置, / em>没有更改。值
2
为FirstDayOfWeek表示星期一
,因为它适用于法国>
- 另一个问题是奇怪,也许是一个错误:每周的第一天弹出窗口似乎影响Java,当设置为更大的区域更改的一部分,但手动选择弹出弹出菜单重置为
。 United States
恢复Java属性,这是一致的和预期的:语言环境:en_US | FirstDayOfWeek:1 | MinimialDaysInFirstWeek:1
系统偏好设置>语言&文字>语言
在选项卡上,将
Français
立即运行IDE。
语言代码:fr_FR | FirstDayOfWeek:1 | MinimialDaysInFirstWeek:1
现在我们知道Java 语言是由Mac 语言设置决定的。
因此,您认为Mac Language 决定Java区域设置,而Java区域设置不是会影响日历属性吗?当上面阅读时,正确,但是当阅读下一节时,我们看到Java Locale以另一种方式设置可以影响日历属性。非常混乱。
传递Java语言环境
另一个矛盾发现。让我们将Mac还原到美国默认值:(1)英语在语言列表顶部,(2)区域设置为美国。
更改我们的代码以将Locale传递到日历的构造函数。
日历c = Calendar.getInstance Locale.FRANCE);
这会影响日历属性:
FirstDayOfWeek:2 | MinimialDaysInFirstWeek:4
因此,混淆的矛盾是:
- 通过Mac的语言设置Java区域设置 不会影响日历的属性。
- 显式地将Locale传递到日历构造函数 会影响其属性。
These two questions prompted me to wonder what settings in Mac OS X affect the Locale and Calendar defaults and behavior in Java:
- WEEK_OF_YEAR inconsistent on different machines
- Why would Calendar.getInstance() fail to use the default locale?
Key in those discussions are these two properties in Calendar:
The default for both those values is
1
in Java 7 & 8 when run on a default United States. What can cause other values to be reported?解决方案I've seen some peculiar behavior as to what affects these properties of java.util.Calendar.
Conclusions
The facts determined:
- The Java
Locale
is determined by Language in System Preferences. - The two properties of Calendar are not affected by the Java Locale changed via the Mac’s Language. Instead they are determined by choosing a Region in System Preferences.
- Oddly enough, and possibly a bug, manually choosing First day of week popup menu in System Preferences fails to affect the equivalent property in Java. Affecting that Mac setting as part of choosing Region affects Java, yet manually choosing the popup menu does not.
- Setting the Java Locale via the Mac Language setting does not affect the Calendar's properties, yet passing a Locale to the Calendar's constructor does affect its properties (an apparent contradiction).
Details
Running this code as a test.
import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; public class TestCalendar { public static void main( String[] args ) { Locale locale = Locale.getDefault(); Calendar c = Calendar.getInstance(); c.setTime( new Date( new Long( 1293840000000l ) ) ); // First moment of the year 2011 in UTC. System.out.println( "Locale: " + locale + " | FirstDayOfWeek: " + c.getFirstDayOfWeek() + " | MinimialDaysInFirstWeek: " + c.getMinimalDaysInFirstWeek() ); } }
Using Mac OS X 10.8.5 (Mountain Lion) in a Parallels 9 virtual machine hosted on Mac OS X (Mavericks) with Java 8 Update 11 with a United States locale chosen during installation of the OS, I played around with
System Preferences
>Language & Text
.System Preferences > Language & Text > Region > First day of week
Strangely, changing
First day of week
on the Region tab has no effect. Java reportsFirstDayOfWeek: 1
whether I set that popup menu to "Sunday" or "Monday".Locale: en_US | FirstDayOfWeek: 1 | MinimialDaysInFirstWeek: 1
Restarting the NetBeans IDE does not help. Restarting the Mac (virtual machine) does not help.
System Preferences > Language & Text > Region
On the Region tab, check the Show all regions checkbox to see many more regions. Choose
French
>France
. Run the IDE immediately. No need no restart the IDE or the OS, nor even to close the System Preferences window.Locale: en_US | FirstDayOfWeek: 2 | MinimialDaysInFirstWeek: 4
Interesting on two accounts.
- Now we know the Region setting affects both of these key Calendar settings, yet the Locale has not changed. The value
2
as FirstDayOfWeek meansMonday
, as is correct for France (and much of the world). - The other issue is bizarre, perhaps a bug: The First day of week popup seems to affect Java when set as part of a larger Region change but manually selecting that popup does not affect the Java properties in question.
Resetting the Region popup back to
United States
restores the Java properties, which is consistent and expected:Locale: en_US | FirstDayOfWeek: 1 | MinimialDaysInFirstWeek: 1
System Preferences > Language & Text > Language
On the Language tab, drag
Français
(French) to the top of the list, so it appears before English.Immediately run the IDE.
Locale: fr_FR | FirstDayOfWeek: 1 | MinimialDaysInFirstWeek: 1
Again, interesting. Now we know the Java Locale is determined by the Mac Language setting. And we know that has no effect on the Calendar properties in question.
So you think Mac Language determines Java Locale, and Java Locale does not affect the Calendar properties? Right, when reading above, but Wrong when reading on to next section where we see that Java Locale set another way can affect the Calendar properties. Very confusing.
Pass Java Locale
Another contradiction found. Let's restore the Mac back to US defaults: (1) English at top of Language list, (2) Region set to United States.
Change our code to pass a Locale to the Calendar's constructor.
Calendar c = Calendar.getInstance( Locale.FRANCE );
This affects the Calendar properties:
FirstDayOfWeek: 2 | MinimialDaysInFirstWeek: 4
So, the confusing contradiction is:
- Setting the Java Locale via the Mac's Language does not affect the Calendar's properties.
- Explicitly passing the Locale to the Calendar constructor does affect its properties.
这篇关于Mac OS X中的什么设置影响Java中的“区域设置”和“日历”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!