How to set first day of week in a Java application calendar

alwbtc picture alwbtc · Aug 8, 2012 · Viewed 28.4k times · Source

We use a java application, it has a date selection field, when you click there a small calendar opens. First day of the week is Sunday there. But I want it to be Monday. I try to change it from Windows Control Panel from Date settings. I set Windows calendar's first day to Thursday, for instance. But in Java application's calendar, first day of the week is still Sunday. Is it possible to change the Java application's first day of the week from Windows, or is it only changed from Java application's code?

Regards

Answer

Next Door Engineer picture Next Door Engineer · Aug 8, 2012

You can use the method setFirstDayOfWeek() to set the first day of the week. The method can only affect the return values of WEEK_OF_MONTH or WEEK_OF_YEAR. For DAY_OF_WEEK, it does nothing.

You can implement something like:

Calendar cal = Calendar.getInstance();
cal.setFirstDayOfWeek(Calendar.MONDAY);
int rec = cal.get(Calendar.WEEK_OF_MONTH);
System.out.println(rec);

Read more on the API HERE