public long dateDiff(String startDate, String endDate) { SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd" ); GregorianCalendar endGC = new GregorianCalendar(); long times, days1 = 0l; try { times = sd.parse(endDate).getTime() - sd.parse(startDate).getTime(); long days = times / (1000 * 24 * 60 * 60); days1 = (days / 7) * 5; long days2 = days % 7; endGC.setTime(sd.parse(endDate)); int weekDay = endGC.get(Calendar.DAY_OF_WEEK ); if (weekDay == 1) { days1 += days2 > 2 ? days2 - 2 : 0; } else if (weekDay == 7) { days1 += days2 > 1 ? days2 - 1 : 0; } else if (weekDay - 1 < days2) { days1 += days2 - 2; } else if (weekDay - 1 > days2) { days1 += days2; } else if (weekDay - 1 == days2) { days1 += weekDay - 1; } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return days1; }