Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[[NSDate date]timeIntervalSince1970] seems to be 1hr behind

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?

like image 455
MikeT Avatar asked Jul 18 '11 23:07

MikeT


1 Answers

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.

like image 163
Tommy Avatar answered Oct 03 '22 19:10

Tommy