• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
bella-java-blog
博客园    首页    新随笔    联系   管理    订阅  订阅

calculate Leave Days

//根据传入的日期得到周末.
public static int getDayOfWeek(Date date){
Calendar cal=Calendar.getInstance();
cal.setTime(date);
int dayNum=0;
if(cal.get(Calendar.DAY_OF_WEEK)==1){
dayNum = 7;
}else{
dayNum=cal.get(Calendar.DAY_OF_WEEK)-1;
}
return dayNum;
}

//get holidays except weekends //得到除周末以外的节假日.
public int getHolidayDays(Date startDate, Date endDate, String employeeId) {
int weekends = 0;
List<Holiday> l = holidayService.getHolidayList(startDate, endDate,
employeeId);
if (l == null) {
return 0;
} else {
for (Holiday h : l) {
int dayNum = DateTimeUtil.getDayOfWeek(h.getHolidayDate());
if (dayNum == 6 || dayNum == 7) {
weekends = weekends + 1;
}
}
}
return l.size() - weekends;
}

//得到两个日期除周末外之间的天数
public static int getWorkDays(Date startDate,Date endDate) throws ParseException {
int workdays = 0;
while (startDate.compareTo(endDate) <= 0) {
if (getDayOfWeek(startDate) != 6 && getDayOfWeek(startDate) != 7){
workdays++;
}
startDate=getNextDate(startDate);
}
return workdays;
}
//得到下一个日期
public static Date getNextDate(Date date){
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, 1);
return cal.getTime();
}

public static Boolean isWeekendsDays(Date date) {
int dayNum = getDayOfWeek(date);
return dayNum == 6 || dayNum == 7;
}

posted @ 2014-06-20 11:17  bella-java-blog  阅读(234)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3