Question:
I'm trying to change default firstDayOfWeek for java.util.Calendar from SUNDAY to MONDAY. Is it possible to achieve this through JVM configuration instead of adding this piece of code?
cal.setFirstDayOfWeek(Calendar.MONDAY);
Answer:
The first day of the week is derived from the current locale. If you don't set the locale of the calendar (Calendar.getInstance(Locale), or new GregorianCalendar(Locale)), it will use the system's default. The system's default can be overridden by a JVM parameter:
This should show a different output with different JVM parameters for language/country:
-Duser.language=en -Duser.country=US -> en_US: 1 (Sunday)
-Duser.language=en -Duser.country=GB -> en_GB: 2 (Monday)
本文介绍如何通过JVM参数设置将Java中默认的工作周起始日从周日更改为周一,避免每次实例化Calendar类时都需要手动设置。

被折叠的 条评论
为什么被折叠?



