NSDate *firstDate = ...NSDate *secondDate = ...NSDate *myDate = [NSDate date];switch ([myDate compare:firstDate]) { case NSOrderedAscending: NSLog(@"myDate is older"); // do something break; case NSOrderedSame: NSLog(@"myDate is the same as firstDate"); // do something break; case NSOrderedDescending: NSLog(@"myDate is more recent"); // do something break;}switch ([myDate compare:secondDate]) { case NSOrderedAscending: NSLog(@"myDate is older"); // do something break; case NSOrderedSame: NSLog(@"myDate is the same as secondDate"); // do something break; case NSOrderedDescending: NSLog(@"myDate is more recent"); // do something break;}
或者更简单地说:
BOol between = NO;if (([myDate compare:firstDate] == NSOrderedDescending) && ([myDate compare:secondDate] == NSOrderedAscending)) { between = YES;}
我确信有更好的方法来进行复杂的日期比较,但这应该有效.
总结以上是内存溢出为你收集整理的可可 – 两个给定的NSDate之间的NSDate全部内容,希望文章能够帮你解决可可 – 两个给定的NSDate之间的NSDate所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)