参数:开始日期,结束日期 String
返回值:天数 int
@SuppressWarnings("deprecation")
public int getDutyDays(String strStartDate,String strEndDate) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date startDate=null;
Date endDate = null;
try {
startDate=df.parse(strStartDate);
endDate = df.parse(strEndDate);
} catch (ParseException e) {
System.out.println("非法的日期格式,无法进行转换");
e.printStackTrace();
}
int result = 0;
while (startDate.compareTo(endDate) <= 0) {
if (startDate.getDay() != 6 && startDate.getDay() != 0)
result++;
startDate.setDate(startDate.getDate() + 1);
}
return result;
}转自【http://www.blogjava.net/pcenshao/archive/2011/11/18/364149.html】
本文提供了一种计算两个日期间的工作日数量的方法。通过解析指定格式的字符串日期,并使用Java循环遍历开始日期到结束日期之间的每一天,排除周末(周六和周日),从而得出工作日的总数。
815

被折叠的 条评论
为什么被折叠?



