
我今天的日期是yyyy-MM-dd格式.我需要检查这个条件
if([displaydate text]<currentdate){ //stop next action } 这里如果displaydate小于今天的日期,那么它必须输入该条件.
解决方法NSDate *today = [NSDate date]; // it will give you current dateNSDate *newDate = [dateFormatter dateWithString:@"xxxxxx"]; // your date NSComparisonResult result; //has three possible values: NSOrderedSame,NSOrderedDescending,NSOrderedAscendingresult = [today compare:newDate]; // comparing two datesif(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之前的日期?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)