title: How to get list of months & years between two dates
body: <p>I need your help in getting the list of months and the years in String between two dates. The user will enter two dates in the String format of:</p>
  
  <pre><code>String date1 ="JAN-2015";
  String date2 ="APR-2015";
  </code></pre>
  
  <p>So the result should be:</p>
  
  <ul>
  <li>Jan-2015</li>
  <li>FEB-2015</li>
  <li>MAR-2015</li>
  </ul>
  
  <p>I tried using the following code but it gave me wrong results:</p>
  
  <pre><code>List&lt;Date&gt; dates = new ArrayList&lt;Date&gt;();
  
  String str_date ="JAN-2015";
  String end_date ="APR-2015";
  
  DateFormat formatter ; 
  
  formatter = new SimpleDateFormat("MMM-yyyy");
  Date  startDate = formatter.parse(str_date); 
  Date  endDate = formatter.parse(end_date);
  long endTime =endDate.getTime() ; 
  long curTime = startDate.getTime();
  while (curTime &lt;= endTime) {
      dates.add(new Date(curTime));
      curTime ++;
  }
  for(int i=0;i&lt;dates.size();i++){
      Date lDate =(Date)dates.get(i);
      String ds = formatter.format(lDate);    
      System.out.println(ds);
  }
  </code></pre>