Why would Calendar.getInstance() fail to use the default locale?

我与影子孤独终老i 提交于 2020-01-15 03:48:07

问题


Yesterday I have received the answer to a question here: WEEK_OF_YEAR inconsistent on different machines

(basically, learned how WEEK_OF_YEAR gets computed based on firstDayOfWeek and minimalDaysInFirstWeek)

But now I have a follow-up question - what other settings could be affecting a Calendar's ability to use the default locale? Because here's the behaviour that I am observing (having a correct en_US default locale):

Calendar c = Calendar.getInstance(); // should use the default locale, per docs
System.out.println(c.getFirstDayOfWeek());
System.out.println(c.getMinimalDaysInFirstWeek());
c = Calendar.getInstance(Locale.getDefault()); // provide the default explicitly
System.out.println(c.getFirstDayOfWeek());
System.out.println(c.getMinimalDaysInFirstWeek());

The output of running this is:

  • 2
  • 4
  • 1
  • 1

It looks even more absurd (setDefault to the results of getDefault...?!) if I run this in Clojure (a JVM language, so the behaviour is exactly the same):

user=> (.getFirstDayOfWeek  (java.util.Calendar/getInstance))
2
user=> (Locale/setDefault (Locale/getDefault))
nil
user=> (.getFirstDayOfWeek  (java.util.Calendar/getInstance))
1

The examples above are run without any JVM arguments whatsoever - so, my question is, where could the setting of 2 and 4 for the firstDayOfWeek and minimalDaysInWeek be coming from? And, perhaps most importantly - how do I fix them permanently?

Thanks!

来源:https://stackoverflow.com/questions/24842731/why-would-calendar-getinstance-fail-to-use-the-default-locale

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!