获取某一个月的全部工作日

 1     public static List<Date> getWorkDates(int year, int month) {
 2         List<Date> dates = new ArrayList<>();
 3         Calendar cal = Calendar.getInstance();
 4         cal.set(Calendar.YEAR, year);
 5         cal.set(Calendar.MONTH, month - 1);
 6         cal.set(Calendar.DATE, 1);
 7         while (cal.get(Calendar.YEAR) == year &&
 8                 cal.get(Calendar.MONTH) < month) {
 9             int day = cal.get(Calendar.DAY_OF_WEEK);
10 
11             if (!(day == Calendar.SUNDAY || day == Calendar.SATURDAY)) {
12                 dates.add((Date) cal.getTime().clone());
13             }
14             cal.add(Calendar.DATE, 1);
15         }
16         return dates;
17     }

 

posted @ 2016-12-30 16:46  yweihainan  阅读(1555)  评论(0编辑  收藏  举报