I need to find the current month and print it. I have the following code:
this.currentDate=LocalDate.now();
this.month = this.currentDate.getMonth();
The problem is that the month is in English and I need to print it in French, to match the rest of the website language. How can I select the language of the month provided by the LocalDate.now()
method without needing to do a manual translation each time I need to display it?
You can convert the Month
type into a String
using getDisplayName()
, which can change the locale to French as follows:
this.currentDate = LocalDate.now();
this.month = this.currentDate.getMonth().getDisplayName(TextStyle.FULL, Locale.FRANCE);