views:

480

answers:

1

I am creating an application. I am running a countdown timer and saving time into a database by converting time into a floating point value (double). Suppose I start the timer at 2.00 PM and set the countdown for 3 hours. After 1 hour I quit the application and on relaunch I am getting time stored from database. Count the difference between stored time and current time I restore the timer according to that, but what if I quit the application and change the time zone to something else?

How do I handle this or how do I fix a specific time zone so that even user changes the time zone the timer always works perfect?

+4  A: 

I don't know the iPhone SDK, but the traditional way of doing this would be to find the time in UTC - often expressed in terms of "milliseconds since Jan 1st 1970" or something similar.

That way the time zone of the device is irrelevant.

EDIT: Looking at the docs for NSDate, I think timeIntervalSince1970 is what you want. That should always be in terms of UTC.

Jon Skeet