得到指定年份的所有周末 博客分类: java 周末日期
程序员文章站
2024-03-16 18:50:04
...
/**
* 得到指定年份的所有周末
*/
public static List<Date> getWeekDayList(int year) {
List<Date> listDate = new ArrayList<Date>();
int i = 1;
Calendar calendar = new GregorianCalendar(year, 0, 1);
while (calendar.get(Calendar.YEAR) < year + 1) {
calendar.set(Calendar.WEEK_OF_YEAR, i++);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
if (calendar.get(Calendar.YEAR) == year) {
listDate.add(calendar.getTime());
}
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
if (calendar.get(Calendar.YEAR) == year) {
listDate.add(calendar.getTime());
}
}
return listDate;
}
* 得到指定年份的所有周末
*/
public static List<Date> getWeekDayList(int year) {
List<Date> listDate = new ArrayList<Date>();
int i = 1;
Calendar calendar = new GregorianCalendar(year, 0, 1);
while (calendar.get(Calendar.YEAR) < year + 1) {
calendar.set(Calendar.WEEK_OF_YEAR, i++);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
if (calendar.get(Calendar.YEAR) == year) {
listDate.add(calendar.getTime());
}
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
if (calendar.get(Calendar.YEAR) == year) {
listDate.add(calendar.getTime());
}
}
return listDate;
}