I have the following two date strings: (1) 24/04/2013 and (2) 19/03/2013 I'm trying to convert these dates into Islamic (Um Al Qura) dates, I'm using this code block to do so:
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateFormat = @"dd/MM/yyyy";
df.calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *dateInGrogrian = [df dateFromString:@"24/04/2013"];
NSDateFormatter *df2 = [[NSDateFormatter alloc] init];
NSCalendar * cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSIslamicCalendar];
[df2 setCalendar:cal];
[df2 setDateFormat:@"dd/MM/yyyy"];
NSLog(@"Converted date to Islamic = %@",[df2 stringFromDate:dateInGrogrian]);
if the input string was 24/04/2013 the NSLog
displayed:
Converted date to Islamic = 14/06/1434
which is correct (according to the formal Islamic calendar which is used in all Islamic countries). But if the input string was 19/03/2013 the NSLog
displayed:
Converted date to Islamic = 08/05/1434
which is incorrect (according to the Islamic calendar the correct date must be 07/05/1434 which's 1 day behind).
-Notes to consider before you suggest an answer:
(1) I have tried to use the calendar identifier NSIslamicCivilCalendar
instead of NSIslamicCalendar
, but to no avail: one of the converted dates was correct and the other was wrong (1 day behind).
(2) I have tried to use GMT time zone like this: [df2 setTimeZone : [NSTimeZone timeZoneWithName:@"GMT"]];
, this produced a correct converted date for day (2) but incorrect for day (1) (1 day behind).
(3) I have tried combinations of solutions: NSIslamicCivilCalendar
with / without GMT time zone, NSIslamicCalendar
with / without GMT time Zone, but also to no avail ...
can anybody provide a code block that satisfies both dates ? so I ensure that any provided gregorian date string is correctly converted into Islamic date string.
thank you so much.