Baub
Baub

Reputation: 5054

NSDate (Time Elapsed) to Hours

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

Answers (1)

Ole Begemann
Ole Begemann

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

Related Questions