我在學習如何將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