Reputation: 156
I am facing problem to find current Islamic date, I have search from stackoverflow and found some solution but those are not the exact solution what I need. Here is my code which give me output as الأربعاء, أبريل ١٩, ٢٠١٧ but I want to show the date as "17th Jumada Al-Awwal 1438" format. the date should be written in English.
Locale locale = new Locale("ar");
SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM dd, yyy", locale);
Date currDate = new Date();
String formattedDate = sdf.format(currDate);
Upvotes: 2
Views: 7205
Reputation: 44061
As far as I know, there is no built-in support for islamic calendar on Android unless you are willing to limit your app to API-level 24 (and if you like the old-fashioned API-style of ICU4J-class contributed by IBM ;-)). But maybe you can consider my library Time4A and then use this code (see also javadoc):
ChronoFormatter<HijriCalendar> hijriFormat =
ChronoFormatter.setUp(HijriCalendar.family(), Locale.ENGLISH)
.addEnglishOrdinal(HijriCalendar.DAY_OF_MONTH)
.addPattern(" MMMM yyyy", PatternType.CLDR)
.build()
.withCalendarVariant(HijriCalendar.VARIANT_UMALQURA);
// conversion from gregorian to hijri-umalqura valid at noon
// (not really valid in the evening when next islamic day starts)
HijriCalendar today =
SystemClock.inLocalView().today().transform(
HijriCalendar.class,
HijriCalendar.VARIANT_UMALQURA
);
System.out.println(hijriFormat.format(today)); // 22nd Rajab 1438
// taking into account the specific start of day for Hijri calendar
HijriCalendar todayExact =
SystemClock.inLocalView().now(
HijriCalendar.family(),
HijriCalendar.VARIANT_UMALQURA,
StartOfDay.EVENING // simple approximation => 18:00
).toDate();
System.out.println(hijriFormat.format(todayExact)); // 22nd Rajab 1438 (23rd after 18:00)
About the language support, all text resources are overtaken from CLDR-v30-data (Unicode-consortium). For example in English: "Jumada II" denotes the 6th month of the year. If you don't like it, you might also provide your own texts. The formatter-builder has a dedicated method to do this.
Upvotes: 2