What is the best way to share a date between a PHP backend and iOS?
Is it safe to both use an epoch timestamp? Or will that vary depending on the time zone?
What is the best way to share a date between a PHP backend and iOS?
Is it safe to both use an epoch timestamp? Or will that vary depending on the time zone?
You could use a unix timestamp, but have the server make it as a UTC time, and also have the app read it as a UTC timestamp. Then you can do the timezone locally on the app to display the correct time.
NOt only a date, you can share any kind of data between applications on multiple platforms if you find solutions like SOAP or RabittMQ.
Why not use a protocol created to synchronize time (NTP)?
http://sv.wikipedia.org/wiki/Network_Time_Protocol
See: Network Time Protocol for iPhone for an ios lib
For transferring "dates" or "time stamps", you may take a look at RFC 3339 which describes the preferred format to represent a "timestamp" on the Internet.
If you're asking about date formats, you probably want to use RFC 3339/ISO 8601 date format, where today, at 8:51:23.632 am in NYC, is represented as 2013-13-08T15:51:23.632Z
(where the time has been converted to "zulu" (GMT)).
NSDate *date = [NSDate date];
NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.locale = enUSPOSIXLocale;
formatter.dateFormat = @"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSS'Z'";
formatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
NSString *dateString = [formatter stringFromDate:date];
NSLog(@"%@", dateString);
If you're talking about the content of your date timestamps, always be wary about using device timestamps in server code. If this was a true transaction processing system, you'd want to make sure that you have one "owner" of the timestamps. For example, when posting an update to a server, I might keep the user's timestamp for reference purposes, but I'd use the server's own generated timestamp within the internal database, using the server's own clock, not relying upon the timestamps provided by the client.