2013年10月4日 星期五

java-dow date of week


java date find Sundary, Saturday
java-date


inf : http://stackoverflow.com/questions/9909361/how-can-i-find-saturdays-and-sundays-in-a-given-month




// This takes a 1-based month, e.g. January=1. If you want to use a 0-based
// month, remove the "- 1" later on.
public int countWeekendDays(int year, int month) {
Calendar calendar = Calendar.getInstance();
// Note that month is 0-based in calendar, bizarrely.
calendar.set(year, month - 1, 1);
int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
int count = 0;
for (int day = 1; day <= daysInMonth; day++) {
calendar.set(year, month - 1, day);
int i= calendar.get(Calendar.DAY_OF_WEEK);
if (i== Calendar.SUNDAY || i == Calendar.SATURDAY) {
count++;
// Or do whatever you need to with the result.
}
}
return count;
}

沒有留言:

張貼留言