tl;dr
the today's date in the desired format
System.out.println(
LocalDate.now().format(
DateTimeFormatter.ofPattern(
"MMMM, d uuuu",
Locale.ENGLISH
)
)
);
Explanation
You're attempt to retrieve the currentDate in the format MMMM d, YYYY does not work because you don't produce the String
output.
Instead, you try to parse(currentDate, formatter)
, wich cannot won't be working either due to an unexpected type of the first parameter/argument (expects a String
, you pass a LocalDate
), or — if LocalDate.toString()
is used implicitly — it won't have your custom format.
Demo
Code
public static void main(String[] args) {
// get today's date as LocalDate
LocalDate today = LocalDate.now();
// provide a DateTimeFormatter for the desired OUTPUT
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(
"MMMM d, uuuu",
Locale.ENGLISH
);
// print the resulting LocalDate's toString() (implicitly)
System.out.println("toString(): " + today);
// print the resulting LocalDate formatted by the formatter
System.out.println("formatted: " + today.format(formatter));
}
Output
toString(): 2023-06-26
formatted: June 26, 2023