title: java.time.DateTimeException: Invalid date 'February 29' as '2017' is not a leap year Java
body: <p>I am try to get starting and ending date in Java, i Have List of Month from January to December in <code>JCombobox</code> and Year  <code>JCombobox</code> to Dispay Years.</p>
  
  <p>First i have converted <code>String</code> month to month number and using this Code:</p>
  
  <pre><code>if(month_sands.getSelectedIndex() != -1){
          int monthnumber = month_sands.getSelectedIndex() + 1;
  
           if(monthnumber&gt;=9)
           {
               month=String.valueOf(monthnumber);
  
           }else
           {
               month="0"+String.valueOf(monthnumber);
           }
  
      }
  </code></pre>
  
  <p>Then Later i have Created a String <code>dateString</code> to get the First and Last date of the Selected month using <code>LocalDate</code>, every thing is working fine but when i select February month and Year 2017 it give me Exception <code>java.time.DateTimeException: Invalid date 'February 29' as '2017' is not a leap year</code> </p>
  
  <p>The code to Get the first and last date is</p>
  
  <pre><code>try {
          String dateString = year_sands.getSelectedItem().toString()+"-"+month+"-"+"01";   
          DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.US); 
          LocalDate date = LocalDate.parse(dateString, dateFormat);
          LocalDate startDate=date.withDayOfMonth(1);
          LocalDate endDate = date.withDayOfMonth(date.getMonth().maxLength());
  
          start_date=startDate.toString();
          end_date=endDate.toString();
  
          System.out.println(start_date);
          System.out.println(end_date);
      } catch (Exception e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>I dont know what am doing wrong please some one help me</p>