I have two dates in 24 hours formate like (dd-MMM-yyyy HH:mm). I want to get a difference between these two dates.
My Code : This is getting only dates, I want a number
NSDateComponentsFormatter can do that
NSTimeInterval secondsBetween = [date2 timeIntervalSinceDate:date1];
NSDateComponentsFormatter *formatter = [[NSDateComponentsFormatter alloc] init];
formatter.allowedUnits = NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute;
formatter.unitsStyle = NSDateComponentsFormatterUnitsStyleFull;
NSLog(@"%@", [formatter stringFromTimeInterval:secondsBetween]);
See NSDateComponentsFormatterUnitsStyle for other styles.