The first lettter of the month in French should be capital using java

The problem is that I am writing code containing a method that gives us a date that is in the format "MMM-dd-YYYY" in French. The code is below.

SimpleDateFormat formatter = new SimpleDateFormat("MMM-dd-YYYY", new Locale("FR"));
String formattedDate = formatter.format(new Date());

But it shows that the month contains 4 letters, and the whole month has small frames, for example

févr-01-2016

How can I format it as follows?

Fév-01-2016
+4
source share
3 answers

The names of the French month are common names that are not capitalized.

Dixit l'Académie française: , , , , , , comme quintidi ou décadi, germinal ou vendémiaire. Comme ce sont des noms communs, ils ne doivent pas, sauf en début de phrase, être écrits avec une majuscule et ils prennent, les uns et les autres, la marque du pluriel.

, :

formattedDate = formattedDate.substring(0, 1).toUpperCase() + formattedDate.substring(1)

UPDATE: , - "MMM-dd-YYYY" . - , .

+3

:

org.apache.commons.lang.WordUtils.capitalize(formattedDate)

doc - WordUtils

+1

SimpleDateFormat formatter = new SimpleDateFormat("MMM-dd-YYYY", new Locale("FR"));

        String formattedDate = formatter.format(new Date());
        String newWord = formattedDate.substring(0,3)+formattedDate.substring(3+1);

     String  formattedDate1= newWord.toUpperCase().charAt(0)+newWord.substring(1);

        System.out.println(formattedDate1);
0

Source: https://habr.com/ru/post/1626815/


All Articles