NSDate 计算时间差

NSDateFormatter* formatter = [[NSDateFormatter  alloc]init];

[formatter setDateFormat:@"yyyyMMddhhmmss"];

NSDate* sendData = [formatter dateFromString:sendTime];

NSDate* now = [NSDate date];

NSCalendar* calendar = [[NSCalendaralloc]initWithCalendarIdentifier:NSGregorianCalendar];

NSCalendarUnit  unit =NSCalendarUnitDay;//| NSCalendarUnitMonth | NSCalendarUnitYear;

NSDateComponents* cmp =[calendar components:unit  fromDate:sendData toDate:now options:NSCalendarWrapComponents];

NSLog(@"cmp.second = %li",(long)cmp.second);

if(cmp.second>3) {

returnYES;

}

你可能感兴趣的:(NSDate 计算时间差)