title: How to get number of days between two dates in java?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1555262/calculating-the-difference-between-two-java-date-instances">Calculating the Difference Between Two Java Date Instances</a>  </p>
  </blockquote>
  
  
  
  <p>How do I get number of days between two dates in Java?</p>
  
  <p>What's the best way?  Here is what I got but it's not the best:</p>
  
  <pre><code>public static ConcurrentHashMap&lt;String, String&gt; getWorkingDaysMap(int year, 
      int month, int day){
          int totalworkingdays=0,noofdays=0;
          String nameofday = "";
          ConcurrentHashMap&lt;String,String&gt; workingDaysMap = 
              new ConcurrentHashMap&lt;String,String&gt;();
          Map&lt;String,String&gt; holyDayMap = new LinkedHashMap&lt;String,String&gt;();
          noofdays = findNoOfDays(year,month,day);
  
          for (int i = 1; i &lt;= noofdays; i++) {
              Date date = (new GregorianCalendar(year,month - 1, i)).getTime();
              // year,month,day
              SimpleDateFormat f = new SimpleDateFormat("EEEE");
              nameofday = f.format(date);
  
              String daystr="";
              String monthstr="";
  
              if(i&lt;10)daystr="0";
              if(month&lt;10)monthstr="0";
  
              String formatedDate = daystr+i+"/"+monthstr+month+"/"+year;
  
              if(!(nameofday.equals("Saturday") || nameofday.equals("Sunday"))){
                  workingDaysMap.put(formatedDate,formatedDate);
                  totalworkingdays++;
              }
          }
  
          return workingDaysMap;
      }
  
  public static int findNoOfDays(int year, int month, int day) {
          Calendar calendar = Calendar.getInstance();
          calendar.set(year, month - 1, day);
          int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
          return days;
      }
  </code></pre>