首页 > 其他 > 详细

calculate Leave Days

时间:2014-06-28 11:42:49      阅读:315      评论:0      收藏:0      [点我收藏+]

//根据传入的日期得到周末.
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;
}

calculate Leave Days,布布扣,bubuko.com

calculate Leave Days

原文:http://www.cnblogs.com/bella-life-blog/p/3798919.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!