Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :)

like image 508
Ali Taha Ali Mahboub Avatar asked Sep 07 '25 05:09

Ali Taha Ali Mahboub


1 Answers

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));
like image 60
AlexR Avatar answered Sep 10 '25 01:09

AlexR