1

在 icu4j 中,我们可以像这样按区域设置显示月份名称

 SimpleDateFormat formatter
                = new SimpleDateFormat ("yyyy MMM dd");
        String dateString = formatter.format(calendar.getTime());

在公历中返回带有月份名称的当前日期。
但是否可以使用 icu4j 获取伊斯兰月份的月份名称。

4

1 回答 1

1
ULocale locale = new ULocale("@calendar=islamic");
Calendar islamicCalendar = Calendar.getInstance(locale);

// full date
DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, locale);
System.out.println(df.format(islamicCalendar.getTime()));

// date in "yyyy MMM dd" format
SimpleDateFormat df1 = new SimpleDateFormat ("yyyy MMM dd", locale);
System.out.println(df1.format(islamicCalendar.getTime()));

// name of month 
SimpleDateFormat df2 = new SimpleDateFormat (SimpleDateFormat.MONTH, locale);
System.out.println(df2.format(islamicCalendar.getTime()));

// name of weekday
SimpleDateFormat df3 = new SimpleDateFormat (SimpleDateFormat.WEEKDAY, locale);
System.out.println(df3.format(islamicCalendar.getTime()));

输出:

AH 1438 Rabiʻ I 5, Sun

1438 Rab. I 05

Rabiʻ I

Sun

如果您希望输出位于特定语言环境中,请将该语言环境放在之前@calendar=islamic

阿拉伯语语言环境示例:

ULocale locale = new ULocale("ar@calendar=islamic");
...

输出:

الأحد، ٥ ربيع الأول، ١٤٣٨ هـ

١٤٣٨ ربيع الأول ٠٥

ربيع الأول

الأحد
于 2016-12-04T02:51:41.123 回答