Duplicate :
|
|
Duplicate :
|
|
Duplicate :
|
A DESCRIPTION OF THE PROBLEM : The description for the DateTimeFormatter provides two Java snippets which have several issues. These are those two examples: First example: String text = date.toString(formatter); LocalDate date = LocalDate.parse(text, formatter); Second example: DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd"); String text = date.toString(formatter); LocalDate date = LocalDate.parse(text, formatter); The Issues: [1] There is no need to provide both examples in the description; the second is sufficient. [2] Both examples are invalid Java. [3] Both examples reference a variable name "date" before it is declared. [4] Both examples pass method "toString()" a "DateTimeFormatter" argument, but no such method exists in the JDK. Presumably the calls should be to method format() rather than toString(). EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - A clearer and valid example for the DateTimeFormatter documentation might be: LocalDate date1 = LocalDate.of(2014, 10, 25); System.out.println("date1: " + date1.toString()); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd"); String text = date1.format(formatter); LocalDate date2 = LocalDate.parse(text, formatter); System.out.println("date2: " + date2.toString()); ACTUAL - The following erroneous text appears in the DateTimeFormatter documentation: String text = date.toString(formatter); LocalDate date = LocalDate.parse(text, formatter); ..... DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy MM dd"); String text = date.toString(formatter); LocalDate date = LocalDate.parse(text, formatter); URL OF FAULTY DOCUMENTATION : http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
|