我怎样才能比较两个日期的返回天数。例如:失去X天的杯子。 看我的代码。如何比较两个日期,返回天数
NSDateFormatter *df = [[NSDateFormatter alloc]init];
[df setDateFormat:@"d MMMM,yyyy"];
NSDate *date1 = [df dateFromString:@"11-05-2010"];
NSDate *date2 = [df dateFromString:@"11-06-2010"];
NSTimeInterval interval = [date2 timeIntervalSinceDate:date1];
//int days = (int)interval/30;
//int months = (interval - (months/30))/30;
NSString *timeDiff = [NSString stringWithFormat:@"%dMissing%d days of the Cup",date1,date2, fabs(interval)];
label.text = timeDiff; // output (Missing X days of the Cup)
你可以检查这个答案 http://stackoverflow.com/questions/13236719/number-of-days-between-two-nsdate-objects它有助于解决我的问题 – 2013-12-13 11:12:51