java获取指定月份的工作日(只去除周六日,没有去除节假日)
程序员文章站
2022-05-18 08:38:19
...
private static int getWorkDays(int theYear, int theMonth) {
// 计算指定月有多少工作日
int workDays = 0;
Calendar cal = Calendar.getInstance();
cal.set(theYear, theMonth - 1, 1);// 从每月1号开始
int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
for (int i = 0; i < days; i++) {
int day = cal.get(Calendar.DAY_OF_WEEK);
if (!(day == Calendar.SUNDAY || day == Calendar.SATURDAY)) {
workDays++;
}
cal.add(Calendar.DATE, 1);
}
return workDays;
}
上一篇: ognl概念和原理详解(转帖)