Java Date Calculate calculateDays(Date startDate, Date endDate)

Here you can find the source of calculateDays(Date startDate, Date endDate)

Description

calculate Days

License

Apache License

Declaration

public static int calculateDays(Date startDate, Date endDate) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static int calculateDays(Date startDate, Date endDate) {
        int presumedDays = 0;

        Calendar startCal = Calendar.getInstance();
        startCal.setTime(startDate);/*from w w w . j  av  a2  s.  c om*/

        Calendar endCal = Calendar.getInstance();
        endCal.setTime(endDate);

        if (startCal.getTimeInMillis() == endCal.getTimeInMillis()) {
            return 0;
        }

        while (startCal.before(endDate)) {
            startCal.add(Calendar.DAY_OF_MONTH, 1);
            presumedDays++;
        }
        return presumedDays;

    }
}

Related

  1. calculaIdadeEmMeses(Date dDataNasc)
  2. calculaIdadeMesAno(Date dDataNasc, String type)
  3. calculate(Date d, int field, int amount)
  4. calculateByDate(Date d, int amount)
  5. calculateDate(Date date, int field, int value)
  6. calculateDurationEndInSec(Date start, int durationInSeconds)
  7. calculateEndDate(Date startDate, int duration)
  8. calculateGestationAge(Date today, Date edd)
  9. calculateLookbackDate(int lookback)