Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 937
alwbtc Avatar asked Aug 08 '12 06:08

alwbtc


People also ask

What is the first day of the week in Java?

By default, java. time uses the ISO 8601 standard. So Monday is the first day of the week (1) and Sunday is last (7).

How do I get day of week in Java?

To get the day of the week, use Calendar. DAY_OF_WEEK.

What is Calendar getInstance () in Java?

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.


2 Answers

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

like image 128
Next Door Engineer Avatar answered Sep 21 '22 18:09

Next Door Engineer


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"));
like image 42
Rajesh Nasit Avatar answered Sep 20 '22 18:09

Rajesh Nasit