title: Java 8 Time API: how to parse string of format "MM.yyyy" to LocalDate
body: <p>I'm a bit discouraged with parsing dates in <em>Java 8 Time API</em>.</p>
  
  <p>Previously I could easily write:</p>
  
  <pre><code>String date = "04.2013";
  DateFormat df = new SimpleDateFormat("MM.yyyy");
  Date d = df.parse(date);
  </code></pre>
  
  <p>But now if I use <em>LocalDate</em> and do it like this:</p>
  
  <pre><code>String date = "04.2013";
  DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM.yyyy");
  LocalDate ld = LocalDate.parse(date, formatter);
  </code></pre>
  
  <p>I receive an exception:</p>
  
  <pre><code>java.time.format.DateTimeParseException: Text '04' could not be parsed at index 0
  java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1948)
  java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1850)
  java.time.LocalDate.parse(LocalDate.java:400)
  java.time.LocalDate.parse(LocalDate.java:385)
  com.luxoft.ath.controllers.JsonController.region(JsonController.java:38)
  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  java.lang.reflect.Method.invoke(Method.java:483)
  org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
  org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
  org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
  org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
  org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
  org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
  org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
  org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
  org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  </code></pre>
  
  <p>If I change string format to <em>"yyyy-MM-dd"</em> everything work perfectly, even without formatter: </p>
  
  <pre><code>String date = "2013-04-12";
  LocalDate ld = LocalDate.parse(date);
  </code></pre>
  
  <p>So my question is: how to parse date in custom format using Java 8 Time API?</p>