Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我需要返回已过期对象的阿拉伯文/法文月份名称_Java_Spring_Internationalization - Fatal编程技术网

Java 我需要返回已过期对象的阿拉伯文/法文月份名称

Java 我需要返回已过期对象的阿拉伯文/法文月份名称,java,spring,internationalization,Java,Spring,Internationalization,我正在处理一个应用程序,我需要返回阿拉伯语/法语的月名和日名,具体取决于我使用的当地语言。 例如,如果本地值为“Ar”,则我需要月份为2月份的“Ar”。如果本地为“Fr”,则月份名称应为Février。 我目前正在解决这个问题,并从不同的.properties文件中读取月份和日期名称。 现在,我的问题是:是否有任何方法可以根据给定的本地名称以不同的语言返回月份和日期名称 非常感谢您的帮助:)您不必为此而努力。使用SimpleDataFormat(格式、区域设置)。下面是代码示例: Sim

我正在处理一个应用程序,我需要返回阿拉伯语/法语的月名和日名,具体取决于我使用的当地语言。 例如,如果本地值为“Ar”,则我需要月份为2月份的“Ar”。如果本地为“Fr”,则月份名称应为Février。 我目前正在解决这个问题,并从不同的.properties文件中读取月份和日期名称。 现在,我的问题是:是否有任何方法可以根据给定的本地名称以不同的语言返回月份和日期名称


非常感谢您的帮助:)

您不必为此而努力。使用
SimpleDataFormat(格式、区域设置)
。下面是代码示例:

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

格式化程序是最灵活的变体。还有一些方便的方法,比如String.format()和printf()也在使用Formatter

Date d = new Date();

Locale saudi = new Locale("ar","SA");

Formatter formatter = new Formatter(System.out,Locale.FRENCH);
formatter.format("month: %tB\n", d);
System.out.printf(saudi, "month: %tB\n", d);
月份:德塞姆布雷

月份:使用类的
getMonths
getWeekdays
方法


尝试以下一种方法:传递format的值,您将以何种格式传递月份名称参数,如“MMM”表示一月


谢谢你们,两种解决方案都很好用。静止数字以英语返回,如1,2,3。是否有任何方法可以根据当地的情况返回,如١、٢、٣、٤?阿拉伯数字可能是不同的故事。首先尝试SimpleNumberFormat。但我不相信这会有帮助。我有一些解析阿拉伯数字的经验,我刚刚编写了自己的解析器,用欧洲的类似物替换阿拉伯数字。
String getMonthName(int month, Locale locale) {
    return DateFormatSymbols.getInstance(locale).getMonths()[month];
}
public static String GetMonthInArabic(Context ctx, String month, String format)
{
    String Mon = month;
    try {
        Date convertedDate = new Date();
        convertedDate = new SimpleDateFormat(format, new Locale("eng")).parse(Mon);
        Mon = new SimpleDateFormat(format, new Locale("ar")).format(convertedDate);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return Mon;
}