我想将当前日期与另一个日期进行比较,如果该日期早于当前日期,那么我应该停止下一个操作.我该怎么做?
我今天的日期是yyyy-MM-dd格式.我需要检查这个条件
if([displaydate text]<currentdate) { //stop next action }
这里如果displaydate小于今天的日期,那么它必须输入该条件.
解决方法
NSDate *today = [NSDate date]; // it will give you current date NSDate *newDate = [dateFormatter dateWithString:@"xxxxxx"]; // your date NSComparisonResult result; //has three possible values: NSOrderedSame,NSOrderedDescending,NSOrderedAscending result = [today compare:newDate]; // comparing two dates if(result==NSOrderedAscending) NSLog(@"today is less"); else if(result==NSOrderedDescending) NSLog(@"newDate is less"); else NSLog(@"Both dates are same");