fork(67) download
  1. import java.text.DateFormat;
  2. import java.text.ParseException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Calendar;
  5. import java.util.Date;
  6. class Test{
  7. public static void main(String[] args) throws ParseException{
  8. DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
  9. Date date1 = df.parse("10/08/2013");
  10. Date date2 = df.parse("21/08/2013");
  11. Calendar cal1 = Calendar.getInstance();
  12. Calendar cal2 = Calendar.getInstance();
  13. cal1.setTime(date1);
  14. cal2.setTime(date2);
  15.  
  16. int numberOfDays = 0;
  17. while (cal1.before(cal2)) {
  18. if ((Calendar.SATURDAY != cal1.get(Calendar.DAY_OF_WEEK))&&(Calendar.SUNDAY != cal1.get(Calendar.DAY_OF_WEEK))) {
  19. numberOfDays++;
  20. cal1.add(Calendar.DATE,1);
  21. }else {
  22. cal1.add(Calendar.DATE,1);
  23. }
  24. }
  25. System.out.println(numberOfDays);
  26. }
  27. }
Success #stdin #stdout 0.1s 380928KB
stdin
Standard input is empty
stdout
7