Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Gregorian Month and Days names to Islamic? NSDate

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.

like image 310
Sobiaholic Avatar asked Oct 28 '12 14:10

Sobiaholic


People also ask

How do you convert Gregorian to Hijri?

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.

What are the 12 Islamic months called?

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.

How can I change my Gregorian from Hijri to Google?

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.

What is Gregorian and Hijri calendar?

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.


2 Answers

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];
like image 199
Pradip Avatar answered Oct 04 '22 11:10

Pradip


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
like image 24
xmhafiz Avatar answered Oct 04 '22 11:10

xmhafiz