Question

I'm doing a calculation to find the NSTimeInterval between a known futureDate (which is in GMT/UTC) and the current time (and timezone) where the device currently resides.

NSTimeInterval approachInterval = [futureDate timeIntervalSinceNow];

I know that NSDate does not store any timeZone specific data, this rather being something that is calculated when the date needs displaying on the device.

My question is that from my initial tests (I'm currently in GMT+0001) it seems that the NSTimeInterval returned does not account for my local timezone. Do I have to manually calculate the timezone offset and remove that from my interval, and what would be the best way of doing that given that I can't supply an NSDate with a correct timezone (using timeIntervalSinceDate: for example)

Was it helpful?

Solution

NSDate represents a single point in time. It does not have (and does not need!!) a time zone. So "a known futureDate (which is in GMT/UTC)" or "I can't supply an NSDate with a correct timezone" does not make sense.

[futureDate timeIntervalSinceNow] returns the time interval between futureDate and the current date and time and is completely independent of any time zones.

If you do not get the expected result, then perhaps your calculation of futureDate was wrong.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top