I need to find all the weekend dates for a given month and a given year.
Eg: For 01(month), 2010(year), the output should be : 2,3,9,10,16,17,23,24,30,31, all week
You could try like this:
int year=2016;
int month=10;
calendar.set(year, 10- 1, 1);
int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
ArrayList sundays = new ArrayList();>
for (int d = 1; d <= daysInMonth; d++) {
calendar.set(Calendar.DAY_OF_MONTH, d);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek==Calendar.SUNDAY) {
calendar.add(Calendar.DATE, d);
sundays.add(calendar.getTime());
}
}