How to compare two date?
问题 I have three dates: (1) previousDate (2) currentDate (3) nextDate, I want to check whether currentDate is later then previous date and earlier than nextDate. How do I do that? 回答1: NSDateFormatter *df= [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy-MM-dd"]; NSDate *dt1 = [[NSDate alloc] init]; NSDate *dt2 = [[NSDate alloc] init]; dt1=[df dateFromString:@"2011-02-25"]; dt2=[df dateFromString:@"2011-03-25"]; NSComparisonResult result = [dt1 compare:dt2]; switch (result) { case