Ios 了解两个日期之间是否有两个日历日过去

Ios 了解两个日期之间是否有两个日历日过去,ios,iphone,objective-c,nsdate,nscalendar,Ios,Iphone,Objective C,Nsdate,Nscalendar,我想知道两个日期之间是否有两个日历日过去了 我试着用 NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit fromDate:date toDate:now options:0]; NSInteger days = [components day]; 并检查天数是否>=2,但似乎只有当一整天过去时才算天数 例如,如果两个日期为: 周一凌晨1:00 星期日晚上11:0

我想知道两个日期之间是否有两个日历日过去了

我试着用

NSDateComponents *components = [[NSCalendar currentCalendar] components:NSDayCalendarUnit fromDate:date toDate:now options:0];
NSInteger days = [components day];  
并检查天数是否>=2,但似乎只有当一整天过去时才算天数

例如,如果两个日期为:
周一凌晨1:00
星期日晚上11:00

结果将为0,
我希望得到1分,因为星期天和星期一不一样

您必须将两个日期“正常化”到各自一天的开始:

NSCalendar *cal = [NSCalendar currentCalendar];
NSDate *startOfToday, *startOfOtherDay;
[cal rangeOfUnit:NSDayCalendarUnit startDate:&startOfToday interval:NULL forDate:now];
[cal rangeOfUnit:NSDayCalendarUnit startDate:&startOfOtherDay interval:NULL forDate:date];
然后计算差值:

NSDateComponents *components = [cal components:NSDayCalendarUnit fromDate:startOfOtherDay toDate:startOfToday options:0];
NSInteger days = [components day];

你能提供更多的代码,比如你的支票日是如何计算的吗