title: Java String to Date object of the format “MM/dd/yyyy HH:mm:ss a”
body: <p>I need to convert a <code>String</code> containing a date into a date object.</p>
  
  <p>The <code>String</code> will be in the format <code>"yyyy-mm-dd HH:mm:ss"</code> and I want the <code>"MM/dd/yyyy HH:mm:ss a "</code> format as result.</p>
  
  <pre><code>String dateString = "2018-03-20 09:31:31";
  
  DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss a", 
                                                             Locale.ENGLISH);
  
  LocalDate date = LocalDate.parse(dateString , formatter);
  </code></pre>
  
  <p>The code above is throwing an exception.</p>