get total hours from nsdate
问题 I'm just looking for a method that calculates the total hours from nsdate (does the same as the TotalHours method in .net) example : 11:30:30 -> 11.5 hours Thanks in advance, 回答1: Get the hour and minute separated with NSDateComponents . NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents *components = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:[NSDate date]]; NSInteger hour = [components hour]; NSInteger minute = [components minute]; Then use