イベントまでの残り日数を示すラベルを作成しようとしています。今日の日付とイベントの日付の差を計算したい。私はこのコードを使用しており、-4600 が返されます。今日の日付を使用するまでは問題なく動作します。
NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"yyyy-MM-dd"];
NSDate *startDate = [NSDate date];
NSDate *endDate = [f dateFromString:end];
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [gregorianCalendar components:NSDayCalendarUnit
fromDate:startDate
toDate:endDate
options:0];
return components.day;
return components.day;