2 日間の差を分単位で計算する必要があります。
NSDate *now = [[NSDate alloc] init];
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
[outputFormatter setDateFormat:@"dd/MM/yyyy hh:mm:ss a"];
NSString* dateStringFromDatabase = @"01/01/1900 11:00:00 AM";
NSDate* dateFromString = [outputFormatter dateFromString:dateStringFromDatabase];
NSString* a = [outputFormatter stringFromDate:now];
NSDate* b = [outputFormatter dateFromString:a];
NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
unsigned int unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit;
NSDateComponents *components = [gregorian components:unitFlags fromDate:dateFromString
toDate:b options:0];
int hours = [components hour];
int minutes = [components minute];
self.lblResult.text = [NSString stringWithFormat:@"%i:%i", hours, minutes];
しかし、次の問題があります。現在の時間については、次のようになります。
2012-10-21 07:37:09 +0000 // wrong it's two hours late
にキャストしようとする@"01/01/1900 11:00:00 AM"
とNSDate
、
1900-01-01 10:00:00 +0000 // also two hours late