ios – 如何比较当前日期与iPhone之前的日期?

我想将当前日期与另一个日期进行比较,如果该日期早于当前日期,那么我应该停止下一个操作.我该怎么做?

我今天的日期是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");

从这个答案How to compare two dates in Objective-C得到你的解决方案

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...