javaspringinternationalization

I need to return Arabic/French month name out of Date object


I am working on an application and I need to return Arabic/French month name and day name, depending on the local I am using. For example, if the local is "Ar" i need the month to be فبراير for February. If local is "Fr" month name should be Février. I am currently working around it and reading the month and day names from different .properties files. Now, my question is: is there any way to return month and day names in different languages depending on the given local?

Your help is much appreciated :)


Solution

  • you do not have to work around it. Use SimpleDateFormat(format, locale). Here is the code example:

        SimpleDateFormat fen = new SimpleDateFormat("dd/MMMM/yyyy", new Locale("en"));
        SimpleDateFormat ffr = new SimpleDateFormat("dd/MMMM/yyyy", new Locale("fr"));
    
        Date date = new Date();
    
        System.out.println(fen.format(date));
        System.out.println(ffr.format(date));