In my app I have to compare two times: current (which is 12:44) and given I tried:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatte
Because your neededDate
will be equal to "1970/01/01 14:45"
.
You need to set correct year and date.
You can get current year, month and say, for example, using next approach:
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:[NSDate date]];
NSLog(@"Current year: %d", components.year);
NSLog(@"Current month: %d", components.month);
NSLog(@"Current day: %d", components.day);