EDIT: This answer is not recommended for older Android (below API level 26). While I expect it to give you the correct day of week always, it will only give a correct um Al-Qura calendar on Java 8 and above and on Android API level 26 and above.
The HijrahDate
of java.time
with default settings gives you the umm Al-Qura calendar:
Locale ar = new Locale("ar");
DateTimeFormatter dayOfWeekFormatter = DateTimeFormatter.ofPattern("EEEE", ar);
HijrahDate today = HijrahDate.now(ZoneId.of("Asia/Riyadh"));
System.out.println("Chronology: " + today.getChronology());
String day = today.format(dayOfWeekFormatter);
System.out.println("aa " + day + " length " + day.length());
Running this snippet today (Hijrah-umalqura AH 1439-10-26) gives:
Chronology: Hijrah-umalqura
aa الثلاثاء length 8
I cannot tell why your code didn’t work. As I said in a comment, I could not reproduce your error. However, the SimpleDateFormat
class that you are using has proved troublesome and is long outdated. So the idea is that if you are programming for Android API level 26 or higher, you throw away SimpleDateFormat
and instead of ummalqura-calendar use the built-in java.time
, the modern Java date and time API, and its HijrahDate
.
I had first suggested that for API levels lower than 26 you could use ThreeTenABP, the Android adaption of ThreeTen Backport, the backport of java.time
for Java 6 and 7. However, in comment Meno Hochschild informs us that this is not reliable:
Even if you have by accident found an example where threeten backport
seems to return the expected result, it will not be the umalqura
calendar. Many dates deviate by one day. Unfortunately, the backport
has not copied the latest state of the Hijri calendar in java.time
but
still uses an older state of threeten development where an algorithmic
version of Hijri calendar had been chosen. If you look at the javadoc
of both libraries you will find a big difference, too. Here, the
backport is no backport at all.
(Since comments on Stack Overflow are sometimes deleted, I quote this one here in its entirity.)
Yet another option on Android is to research whether the library by the same Meno Hochschild, Time4A, will give you what you want. It’s in the third link below. I have no experience with it myself, unfortunately.
Links
and i got
V/MainActivity: month ar ٠٠١ – Mahmoud Mabrok Jul 07 '18 at 17:52