我在学习如何将NSDate
对象与isEqualToDateDate
方法进行比较。我不明白为什么这个简单的测试不会返回true并打印出NSLog
。在此先感谢比较两个NSDate对象不能正常工作
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSDate *myDate = [[NSDate alloc]initWithTimeIntervalSinceNow:4000000];
NSDate *otherDate = [[NSDate alloc]initWithTimeIntervalSinceNow:4000000];
NSLog(@"myDate %@",myDate);
NSLog(@"otherDate %@",otherDate);
if ([myDate isEqualToDate:otherDate]) {
NSLog(@"The dates are the same");
};
[myDate release];
[otherDate release];
[pool drain];
return 0;
}
是的我想你可能是对的 - 我已经改变了方法initWithTimeIntervalSince1970,一切都很好。我没有得到的是这个方法是什么,如果它总是返回false。任何进一步的帮助将是伟大的。 – pete