Reputation: 5054
I am trying to calculate the average speed of the user using Core Location, so I have a total distance traveled in miles (double totalDistance
) and the time elapsed (NSDate *timeElapsed
).
How can I convert timeElapsed
to a double displaying hours? I.e. 0.1 hours, 0.0001 hours, etc so that I can calculate my average speed correctly?
Upvotes: 1
Views: 391
Reputation: 135588
Convert the date object into a NSTimeInterval
(with timeIntervalSinceReferenceDate
or timeIntervalSinceDate:
if you have a different start date), then divide the NSTimeInterval
by 3600.
Upvotes: 2