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
By default, java. time uses the ISO 8601 standard. So Monday is the first day of the week (1) and Sunday is last (7).
To get the day of the week, use Calendar. DAY_OF_WEEK.
The getInstance() method in Calendar class is used to get a calendar using the current time zone and locale of the system. Syntax: public static Calendar getInstance() Parameters: The method does not take any parameters. Return Value: The method returns the calendar.
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
If you want to set Monday then use
Calendar currentCalendar = Calendar.getInstance(new Locale("en","UK"));
If you want to set Sunday then use
Calendar currentCalendar = Calendar.getInstance(new Locale("en","US"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With