If anyone has any ideas on the best way to handle this data please let me know.
It really depends on how you're parsing that JSON data. I won't cover JSON parsing here because there are many, many tutorials and blog posts on that topic. Here's one in case you're not sure where to start.
Your goal is to end up with date objects (Date
in Swift, NSDate
in Objective-C). For example, if you have the values as strings, you can use DateFormatter
to parse the strings into Date
objects.
Once you have those date objects you can use the operations that those objects supply to get a TimeInterval
, which is a double
representing an interval in seconds. Convert that to hours by dividing by 3600:
let interval = endDate.timeIntervalSince(startDate)
let hours = interval / 3600