i am using following method to get date time difference in minutes it giving me negative value .
I am using following code :
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSUInteger unitFlags = NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitMinute;
NSDateComponents *components = [gregorian components:unitFlags
fromDate:dt2
toDate:dt1 options:0];
NSInteger months = [components month];
NSInteger days = [components day];
NSInteger minutes = [components minute];
NSLog(@"months %ld",(long)months);
NSLog(@"days %ld",(long)days);
NSLog(@"minutes %ld",(long)minutes);
int res = (int)minutes;
NSLog(@"int minutes %d",res);
return res;
I want to calculate difference between these two below date in minutes:
- date1:2016-11-23 07:39:44 +0000
- date2:2016-11-23 08:13:44 +0000
As a result I'm getting -34
.