1.创建一个.h 文件
+(int)getTimebySubtracting:(NSDate*)Date1 andDate2:(NSDate*)Date2;
2.在.m文件中对方法
+(int)getTimebySubtracting:(NSDate*)Date1 andDate2:(NSDate*)Date2{
//日期减
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
// unsigned int unitFlags = NSHourCalendarUnit;//年、月、日、时、分、秒、周等等都可以
unsigned int unitFlags = NSDayCalendarUnit;// 日 等等都可以
NSDateComponents *comps = [gregorian components:unitFlags fromDate:Date1 toDate:Date2 options:0];
// int hours = (int)[comps hour];//时间差
int days = (int)[comps day];//时间差
NSLog(@"----days----%d",days);
return days;
}