HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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 – 如何比较当前日期与iPhone之前的日期?全部内容,希望文章能够帮你解决ios – 如何比较当前日期与iPhone之前的日期?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。