Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8177446

DateTimeFormatter parsing error for dd-MM-yyyy format

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      DateTimeFormatter cannot parse date in dd-MM-yyyy format, if the input string contains additional digits, e.g. 12-02-2012123.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.text.ParsePosition;
      import java.time.format.DateTimeFormatter;
      import java.time.format.DateTimeParseException;

      public class DateTest {

          public static void main(String[] args) {
              String input = "12-02-201234";
              String format = "dd-MM-yyyy";

              ParsePosition parsePosition = new ParsePosition(0);
              DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
              formatter.parse(input, parsePosition);
          }
      }
      ---------- END SOURCE ----------

            scolebourne Stephen Colebourne
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: