[Q#269486][A#269538] How to specify firstDayOfWeek for java.util.Calendar using a JVM argument
https://stackoverflow.com/q/269486
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?
Answer
https://stackoverflow.com/a/269538
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: Don't forget that this could change other behavio(u)r too.
APIzation
public static void main(String[] args) {
Calendar c = new GregorianCalendar();
System.out.println(Locale.getDefault() + ": " + c.getFirstDayOfWeek());
}
package com.stackoverflow.api;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
public class Human269538 {
public static int getFirstDayOfWeek() {
Calendar c = new GregorianCalendar();
return c.getFirstDayOfWeek();
}
}
package com.stackoverflow.api;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
/**
* How to specify firstDayOfWeek for java.util.Calendar using a JVM argument
*
* @author APIzator
* @see <a href="https://stackoverflow.com/a/269538">https://stackoverflow.com/a/269538</a>
*/
public class APIzator269538 {
public static void specifyFirstdayofweek() {
Calendar c = new GregorianCalendar();
System.out.println(Locale.getDefault() + ": " + c.getFirstDayOfWeek());
}
}