/**
*
* @Title: getCountday
* @Description: 去除周末的总天数
* @author yjs
* @date 2018年11月9日 上午9:14:11
* @param strStartDate
* @param strEndDate
* @return
* @throws java.text.ParseException
*/
public int getCountday(String strStartDate, String strEndDate) throws java.text.ParseException {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date startDate = null;
Date endDate = null;
startDate = df.parse(strStartDate);
endDate = df.parse(strEndDate);
int result = 0;
while (startDate.compareTo(endDate) <= 0) {
if (startDate.getDay() != 6 && startDate.getDay() != 0)
result++;
startDate.setDate(startDate.getDate() + 1);
}
return result;
}
/**
*
* @Title: dayDiff
* @Description:计算两个字符串日期相差的天数
* @author yjs
* @date 2018年11月9日 下午3:30:54
* @param date1 字符串日期1
* @param date2 字符串日期2
* @param format 日期格式化方式 format="yyyy-MM-dd"
* @return
*/
public static Long dayDiff(String date1, String date2, String format) {
SimpleDateFormat formater = new SimpleDateFormat(format);
Long diff = 0l;
try {
Long d1 = formater.parse(date1).getTime();
Long d2 = formater.parse(date2).getTime();
// diff = (Math.abs(d1 - d2) / (1000 * 60 * 60 * 24));
diff = (d2 - d1) / (1000 * 60 * 60 * 24);
} catch (ParseException e) {
e.printStackTrace();
}
return diff;
}