When I use this code to get the actual date:
String dateActuelle = DateTimeFormatter.ofPattern("dd MMMM uuuu").format(LocalDate.now());
It returns "06 sept. 2021" in french but I would like to get "06 septembre 2021" (full month name).
Do you know how I can do this?
While the accepted answer has correctly described the difference between MMMM
and MMM
, it has missed a piece of crucial information - Locale
. Date-Time parsing/formatting API are Locale
-sensitive and therefore, using an applicable Locale
can save you from surprises and undesired results. Check Always specify a Locale with a date-time formatter for custom formats to learn more about it.
Demo:
class Main {
private static final DateTimeFormatter FORMATTER =
DateTimeFormatter.ofPattern("dd MMMM uuuu", Locale.FRANCE);
public static void main(String[] args) {
LocalDate now = LocalDate.now();
String formatted = now.format(FORMATTER);
System.out.println(formatted);
LocalDate specificDate = LocalDate.of(2025, Month.SEPTEMBER, 10);
System.out.println(specificDate.format(FORMATTER));
}
}
Output from a sample run:
01 avril 2025
10 septembre 2025
Learn more about the modern Date-Time API from Trail: Date Time.