I am using a custom calendar in my app. I have given the users option to select the first day of the week which could be: Saturday, Sunday, Monday
I want to get the number of weeks in a month – depending on when the week starts, overriding the default value of week start – Sunday.
Code:
public int getWeeksOfMonth(int year, int month) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONTH, month-1);
calendar.set(Calendar.YEAR, year);
int numOfWeeksInMonth = calendar.getActualMaximum(Calendar.WEEK_OF_MONTH);
return numOfWeeksInMonth;
}
Try
In your case you might want to do this:
And call the method with a line such as