Java Data Type How to - Count days between two dates


We would like to know how to count days between two dates.


import java.util.Calendar;
//  w  w  w. j a v a  2s . c o  m
public class Main {
  public static void main(String[] args) {
    Calendar startEmployment = Calendar.getInstance();
    startEmployment.set(2010, 2, 1);
    startEmployment.set(2011, Calendar.FEBRUARY, 1);

    Calendar now = Calendar.getInstance();

    long numberOfDays1 = countDays(startEmployment, now);


  private static long countDays(Calendar start, Calendar end) {
    long totalNumberOfDays = 0;
    while (start.before(end)) {
      start.add(Calendar.DAY_OF_MONTH, 1);
    return totalNumberOfDays;

The code above generates the following result.