Checking whether the date is a month-end
807589Oct 27 2008 — edited Oct 27 2008I'm using the following code and I want to check whether the date is a month-end.
public WeekendFinder(int year) {
this.year = year;
cal = Calendar.getInstance();
try {
//Sets the date to the 1st day of the 1st month of the specified year
cal.setTime(new SimpleDateFormat("MM/dd/yyyy").parse("01/01/" + this.year));
} catch (java.text.ParseException e) {
System.err.println("Error parsing date: " + e.getMessage());
e.printStackTrace();
}
weekendList = new ArrayList(53);
weekDaysList = new ArrayList(300);
}
public void findWeekends() {
// The while loop ensures that you are only checking dates in the specified year
while (cal.get(Calendar.YEAR) == this.year) {
// The switch checks the day of the week for Saturdays and Sundays
switch (cal.get(Calendar.DAY_OF_WEEK)) {
case Calendar.FRIDAY:
//Before adding, check for the Month End. If it is a month-end, then do not add date to arraylist
**** How to check for the month -end.. *****
weekendList.add(cal.getTime());
break;
}
// Increment the day of the year for the next iteration of the while loop
cal.add(Calendar.DAY_OF_YEAR, 1);
}
}