I'm trying to get the seconds between two dates, for this I'm using the NSDateComponents:
NSString *start = components2[0];// 2014-10-14 20:52:43
NSString *end = components[0];// 2014-10-14 20:54:40
NSLog(@"Start -> %@, End -> %@",start,end);
NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSDate *startDate = [f dateFromString:start];
NSDate *endDate = [f dateFromString:end];
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components3 = [gregorianCalendar components:NSDayCalendarUnit
fromDate:startDate
toDate:endDate
options:0];
NSLog(@"Seconds -> %ld", (long)[components3 second]);
But I'm receiving the following error:
-[__NSCFCalendar components:fromDate:toDate:options:]: fromDate cannot be nil