Reputation: 2955
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,
Upvotes: 0
Views: 1943
Reputation: 1727
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 this to find the sum.
double totalHours = ((double)hour + (double)minute/60);
Upvotes: 3