As the title, I have tried the following simple code:
NSDate *date1 = [NSDate date];
NSDate *date2 = [NSDate date];
if([date1 compare:date2] == NSOrderedSame)
NSLog(@"two time same");
else
NSLog(@"two time not same");
and the result is:
two time not same
I don't understand that, can someone give me some tips? Thank you.
it's not same because there is a little time difference of creation of object, just try to print there value in NSTimeInterVal to know better.
Example:
NSDate *date1 = [NSDate date];
NSDate *date2 = [NSDate date];
NSLog(@"date1 : %f", [date1 timeIntervalSince1970]);
NSLog(@"date2 : %f", [date2 timeIntervalSince1970]);
Output:
date1 : 1404466511.638555
date2 : 1404466511.638558
and you also can see the difference using method
- (NSTimeInterval)timeIntervalSinceDate:(NSDate *)anotherDate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With