how can I compare two dates return number of days.
Ex: Missing X days of the Cup.
look my code.
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)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…