Here you can find the source of dateDiff(String startDate, String endDate)
public static long dateDiff(String startDate, String endDate)
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.GregorianCalendar; public class Main { public static long dateDiff(String startDate, String endDate) { SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); GregorianCalendar endGC = new GregorianCalendar(); long times, days1 = 0l; try {//from w ww .j a v a 2 s .co m 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; } }