I\'m not trying to format the date in YYYY-MM-DD or dd/MM/YYYY. I\'m asking about the literal format of LocalDate.
I just started learning Java and I am using this IDE c
As discussed in the comments, the solution is to add the code that creates the LocaDate
, but bluej needs the fully qualified class name with the package prefix “java.time.”:
java.time.LocalDate.of(2018, 5, 30)
Not sure why it doesn't work with just LocalDate.of(...)
(even with the class correclty imported), but at least this works.
Just another detail: a date has no format. Classes like LocalDate
just holds values (in this case, it has year, month and day values), but a date itself has no format at all. The same date can be represented in many different formats: May 30th 2018
, 2018-05-30
, 30/05/18
are different formats, but all represent the same date. A date object just holds the values, and you can choose whatever format you want to represent it.
When you print a LocalDate
, it implicity calls toString()
, which by default chooses yyyy-MM-dd
format, which is a ISO 8601 format, but as I said, that's just one of the many possible ways to format a date (although the value always stays the same). Telling that "a date has a format" is wrong and misleading.
Try converting the LocalDate in the call, such as:
TestPaper (2018-05-30, LocalDate.parse("2018/05/30"), 30/05/2018);
There are other static methods within LocalDate you can use. See here for more examples.
From your comment above, don't forget your import:
import java.time.LocalDate;