我正在尝试计算现在和用户定义的日期之间的时间间隔(以天为单位),以便结果在点击按钮时出现在标签中。2个NSDates之间的时间间隔
差异总是-4080我不确定我的方程有什么问题。 谢谢你的帮助
- (void)LabelChange2:(id)sender{
NSDateFormatter *df3 = [[NSDateFormatter alloc] init];
df3.dateStyle = NSDateFormatterMediumStyle;
labelDOB.text = [NSString stringWithFormat:@"%@",
[df3 stringFromDate:datepick.date]];
}
NSDate * df3 = [datePick date];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comps = [gregorian components: NSDayCalendarUnit
fromDate: [NSDate date]
toDate: df3
options: 0];
int days = [comps day];
labelResult.text = [NSString stringWithFormat:@"%i", days];
可能重复[如何确定从现在开始直到NSDate的天数?](http://stackoverflow.com/questions/7959243/how-to-tell-the-amount-of-days-from-现在一直到nsdate) – 2012-03-04 18:41:40