I'm trying to display the Islamic current day
name , month
name. I used NSLocale to set the region to ar_SA
, however it's just translating the day and month names from English to Arabic.
Output I'm getting in Arabic:
١٢ الأحد ، اكتوبر ، ٢٠١٢
which in English is Sunday, October 28, 2012
Output I want:
Al-Ahad, Dul-Hijja 12, 1433
Snippet:
NSDateFormatter *islamicFormatter = [[NSDateFormatter alloc]init];
[islamicFormatter setDateStyle:NSDateFormatterFullStyle];
[islamicFormatter setLocale:[[NSLocale alloc]initWithLocaleIdentifier:@"ar_SA"]];
NSString *islamicDateString = [islamicFormatter stringFromDate:islamicDate];
NSLog(@"%@",islamicDateString);
I hope it's clear for you guys.
If you want to convert a Gregorian date to a Muslim date, you need to subtract 622 from the original year and then multiply by 1.03: Year Muslim = (Year Gregorian– 622) × 1.03.
It is based on a year of 12 months: Muḥarram, Ṣafar, Rabīʿ al-Awwal, Rabīʿ al-Thānī, Jumādā al-Awwal, Jumādā al-Thānī, Rajab, Shaʿbān, Ramaḍān (the month of fasting), Shawwāl, Dhū al-Qaʿdah, and Dhū al-Ḥijjah. Each month begins approximately at the time of the new moon.
On your Android phone or tablet, open your Google app Google Search. Tap More ... > Settings > Language & region > Search region. Tap the region you want to see search results in.
Two calendars are in regular use in the Muslim world: the Gregorian and the Hijri. The Gregorian calendar is named after the Roman Catholic pope, Pope Gregory XIII, while the Hijri is named after the migration (hijrah) of Prophet Muhammad (peace be upon him) from his homeplace, Makkah to the town of Madinah in 622 CE.
I think this would help
NSCalendar * hijri = [[NSCalendar alloc] initWithCalendarIdentifier:NSIslamicCalendar];
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterLongStyle];
[formatter setTimeStyle:NSDateFormatterNoStyle];
[formatter setCalendar:hijri];
NSLog(@"hijri: %@", [formatter stringFromDate:[NSDate date]]);
[formatter release];
I know this post is quite old but I think it is necessary to add Swift 3 code as below for other reference.
let hijri = Calendar(identifier: .islamic)
let formatter = DateFormatter()
formatter.calendar = hijri
formatter.dateFormat = "d MMMM yyyy"
let today = Date()
let dateString = formatter.string(from: today)
print(dateString)
// the output: 16 Jamada II 1438
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With