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

java.time.format.DateTimeFormatter error in API doc example

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8u20
    • core-libs
    • x86
    • windows_8

      A DESCRIPTION OF THE PROBLEM :
      The API docs for DateTimeFormatter explains: "The main date-time classes provide two methods - one for formatting, format(DateTimeFormatter formatter), and one for parsing, parse(CharSequence text, DateTimeFormatter formatter)."

      Then there is an example:

      String text = date.toString(formatter);
      LocalDate date = LocalDate.parse(text, formatter);

      Error: date.toString(formatter); should be: date.format(formatter);

      As explained in the text above there is a "format" method, there is no "toString" method that takes a DateTimeFormatter.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      String text = date.format(formatter);
      ACTUAL -
      String text = date.toString(formatter);

      URL OF FAULTY DOCUMENTATION :
      http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html

            rriggs Roger Riggs
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: