下面的代码显示了问题:从 1435 年的第一天提前一整年不会导致 1436 年的第一天。
任何想法我错过了什么?
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay:1];
[components setMonth:1];
[components setYear:1435];
NSCalendar *islamic = [[NSCalendar alloc] initWithCalendarIdentifier:NSIslamicCalendar];
NSDate *date = [islamic dateFromComponents:components];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setCalendar:islamic];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSLog(@"%@", [dateFormatter stringFromDate:date]); // -> 01.01.1435
NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
[offsetComponents setYear:1];
NSDate *dateWithOffset = [islamic dateByAddingComponents:offsetComponents toDate:date options:0];
NSLog(@"%@", [dateFormatter stringFromDate:dateWithOffset]);
// -> 30.12.1435 ... WHY NOT 01.01.1436 ????