在NSDate
– isEqualToDate: – earlIErDate: – laterDate: – compare:
当你使用 – (NSComparisonResult)compare:(NSDate *)anotherDate,你回到其中之一:
The receiver and anotherDate are exactly equal to each other,NSOrderedSameThe receiver is later in time than anotherDate,NSOrderedDescendingThe receiver is earlIEr in time than anotherDate,NSOrderedAscending.
例:
NSDate * Now = [NSDate date];NSDate * mile = [[NSDate alloc] initWithString:@"2001-03-24 10:45:32 +0600"];NSComparisonResult result = [Now compare:mile];NSLog(@"%@",Now);NSLog(@"%@",mile);switch (result){ case NSOrderedAscending: NSLog(@"%@ is in future from %@",mile,Now); break; case NSOrderedDescending: NSLog(@"%@ is in past from %@",Now); break; case NSOrderedSame: NSLog(@"%@ is the same as %@",Now); break; default: NSLog(@"erorr dates %@,%@",Now); break;}[mile release];总结
以上是内存溢出为你收集整理的如何比较Objective-C中的两个日期全部内容,希望文章能够帮你解决如何比较Objective-C中的两个日期所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)