我需要从Date对象中返回阿拉伯语/法语月份名称

Ali*_*oub 2 java spring internationalization

我正在处理一个应用程序,我需要返回阿拉伯语/法语月份名称和日期名称,具体取决于我使用的本地.例如,如果本地是"Ar",我需要月份为2月的فبراير.如果本地是"Fr"月份名称应该是Février.我目前正在解决它并从不同的.properties文件中读取月和日名称.现在,我的问题是:有没有办法根据给定的本地返回不同语言的月份和日期名称?

非常感谢您的帮助 :)

Ale*_*exR 7

你不必解决它.使用SimpleDateFormat(format, locale).这是代码示例:

    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));
Run Code Online (Sandbox Code Playgroud)