title: Cannot parse local date time in Spring controller
body: <p>In my Spring Boot application, I need to handle a form with date time field and convert it to <code>LocalDateTime</code> in Java.</p>
  
  <p>I specified pattern <code>"YYYY-MM-dd HH:mm"</code> and it fails to convert when I submit the form with input value <code>1990-01-01 10:10</code>.</p>
  
  <p>Here is the form object:</p>
  
  <pre><code>public class UserForm {
      @NotNull
      @DateTimeFormat(pattern = "YYYY-MM-dd HH:mm")
      private LocalDateTime dateTime;
      // getters, setters
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>@RequestMapping("/users")
  @Controller
  public class UserController {
      @GetMapping("")
      public String userForm(UserForm userForm) {
          return "/users/form";
      }
  
      @PostMapping("")
      public String postForm(@Valid UserForm userForm, BindingResult bindingResult) {
          System.out.println(userForm + " " + bindingResult);
          return "/users/form";
      }
  }
  </code></pre>
  
  <p>And Thymeleaf form:</p>
  
  <pre><code>&lt;form th:object="${userForm}" th:action="@{/users}" method="post"&gt;
      &lt;span th:each="err: ${#fields.errors('dateTime')}" th:text="${err}" style="background-color:red;color:white;"/&gt;
      &lt;input type="text" th:field="*{dateTime}"/&gt;
      &lt;input type="submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>What is wrong with this example ? How should I fix it to make it properly parse <code>String</code> to <code>LocalDateTime</code> ?</p>
  
  <p>I also submitted <a href="https://github.com/alexbezhan/localdatetime-binding-error" rel="nofollow noreferrer">example application here</a>.</p>
  
  <p><strong>Update:</strong></p>
  
  <ul>
  <li><p>Under "fails to convert" I mean I'm getting exception:</p>
  
  <p>org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.validation.constraints.NotNull @org.springframework.format.annotation.DateTimeFormat java.time.LocalDateTime] for value 1990-01-01 10:10</p></li>
  <li><p>Using lowercase <code>yyyy</code> fixed the problem. Thanks.</p></li>
  </ul>