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("[email protected]=islamic");
...
輸出:
الأحد، ٥ ربيع الأول، ١٤٣٨ هـ
١٤٣٨ ربيع الأول ٠٥
ربيع الأول
الأحد
相關:https://developer.android.com/guide/topics/resources/icu4j-framework.html –