I have a problem with this code:
NSDate *today = [[NSDate alloc] init];
if (dateOne == today) {
dataLabel.textColor = [UIColor redColor]; NSLog(@"inside if");}
NSLog(@"today:%@", oggi);
NSLog(@"dateOne:%@", dateOne);
the result of console is
2011-06-10 17:19:00.170 Project[678:707] today:2011-06-10 15:19:00 +0000
2011-06-10 17:19:00.174 Project[678:707] dateOne:2011-06-10 15:19:00 +0000
I also try “isEqualToDate” but the code don’t entry inside “if”
I understand you are trying to determine if a given
NSDateis today. To do this you don’t have to take in consideration hours, minutes, etc. in your comparison. How about this:The method
isEqualToDate:won’t do this job because it checks whether a given date is exactly equal the receiver (with sub-second precision).The
==operator is not appropriate for this either because it compares the pointers to the objects, it checks whether the pointers point to the same memory location.