I have a NSDate *da and when i print i get the following string : 2013-10-24 00:00:00 +0000.
NSDateFormatter *form = [[NSDateFormatter alloc] init];
[form setDateFormat:@"yyyy-mm-dd"];
NSDate *myD = [form dateFromString: @"2013-10-24"];
Now what i want to do is to compare NSDate *da and NSDate *myD. If it matches i need to print a NSLog.
if ([da isEqualToDate:myD]) {
NSLog(@"ok");
} else {
NSLog(@"bad");
}
The problem is that myD becomes null. How can i solve this?
UPDATE
Still there's a problem with the formatter; However now it doesn't return NIL.
When i print da i get the output 2013-10-24 13:00:00 +0000 and when i print myD i get the output 2013-10-23 18:30:00 +0000. Why didn't this get format correctly. I think there still exist some error in the formatting part of my code. Help
UPDATE 2
NSDate *da = [NSDate date]; ///// PRINTS 2013-09-16 11:52:40 +0000
NSDateFormatter *form = [[NSDateFormatter alloc] init];
[form setDateFormat:@"yyyy-MM-dd"];
NSDate *myD = [form dateFromString: @"2013-09-16"]; ////// PRINTS 2013-09-16 00:00:00 +0000