I am writing an app that communicates with some web services. When a variable is updated on the server, it will return a unix timestamp to tell me when it was updated. I can then compare it using:
[[NSDate date]timeIntervalSince1970]
to keep things in sync.
The system time on the iPhone is correct. But unix time seems to be 1hr behind the server(and system time as shown on the clock). Why is this happening? Do I need to set a time zone?
timeIntervalSince1970
is defined to return:
The interval between the receiver and the reference date, 1 January 1970, GMT.
Is it possible you're comparing to a time that is defined to be from 1 January 1970 in some other timezone? If so, the easiest thing to do is to use timeIntervalSinceDate:
rather than timeIntervalSince1970
, possibly having used NSDate's dateByAddingTimeInterval:
to move from the reference date in GMT to the reference date in your ideal time zone.
You can use NSTimeZone's secondsFromGMTForDate:
property if you don't want to hard code things.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With