title: Using new Java 8 DateTimeFormatter to do strict date parsing
body: <p>I have a simple problem : I want to parse Java strings in format <code>"yyyyMMdd"</code> strictly, so that <code>"19800229"</code> is a valid date, but <code>"19820229"</code> is not. Assume these are AD dates from the normal Gregorian calendar.</p>
  
  <p>I am trying to use the new <code>java.time</code> package from JDK 8 to solve this problem, but it is proving more complicated than hoped. My current code is:</p>
  
  <pre><code>private static final DateTimeFormatter FORMAT = DateTimeFormatter
          .ofPattern("yyyyMMdd").withChronology(IsoChronology.INSTANCE)
          .withResolverStyle(STRICT);
  
  public static LocalDate parse(String yyyyMMdd) {
      return LocalDate.parse(yyyyMMdd, FORMAT);
  }
  </code></pre>
  
  <p>However, parsing a valid date such as "19800228" produces what to me is an incomprehensible error:</p>
  
  <blockquote>
    <p>java.time.format.DateTimeParseException: Text '19820228' could not be parsed: Unable to obtain LocalDate from TemporalAccessor: {MonthOfYear=2, DayOfMonth=28, YearOfEra=1982},ISO of type java.time.format.Parsed</p>
  </blockquote>
  
  <p>How do I use <code>java.time.format.DateTimeFormatter</code> to solve my simple use case?</p>