Martin Vysny
Martin Vysny

Reputation: 3201

Is first-day-of-week language-based or country-based on JVM?

One can obtain the first day of week on JVM by calling Calendar.getInstance(locale).getFirstDayOfWeek(). Yet, is this information language-based, or country-based?

Upvotes: 7

Views: 340

Answers (2)

Martin Vysny
Martin Vysny

Reputation: 3201

As it turns out, this is JDK version-dependent. JDK8 returns first day of week based on language, so it returns SUNDAY for "en_FI" "en_US" and MONDAY for "fi_FI" and "fi_US".

However, JDK9 switched to the CLDR system which (more logically) uses country. So, JDK9 will return MONDAY both for "en_FI" and "fi_FI" locales, and will return SUNDAY for "fi_US" and "en_US".

See JEP 252 for more details.

Also, quoting from JDK-8203280:

To add an explanation to this behavior, the CLDR implementation is correct, i.e., the first day of week should be defined by the region, not by the language.

Upvotes: 8

Andreas Hartmann
Andreas Hartmann

Reputation: 1883

According to the documentation, it is country-based: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#getFirstDayOfWeek()

Gets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France.

Upvotes: 1

Related Questions