0

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?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user2955517
  • 273
  • 3
  • 5
  • 1
    You certain do you have to be that the time is correct? Is it a bankapp with certificate's that has validity dates? Or whats the app? Whats your definition of "safe"? – netdigger Nov 08 '13 at 13:42

5 Answers5

1

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.

Martin Alderson
  • 892
  • 1
  • 7
  • 14
  • Another reason to use a unix timestamp is that you won't have to create a date formatter to turn the string into an NSDate. – hukir Nov 08 '13 at 14:02
0

NOt only a date, you can share any kind of data between applications on multiple platforms if you find solutions like SOAP or RabittMQ.

rernesto
  • 554
  • 4
  • 11
0

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

Community
  • 1
  • 1
netdigger
  • 3,659
  • 3
  • 26
  • 49
0

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.

Community
  • 1
  • 1
CouchDeveloper
  • 18,174
  • 3
  • 45
  • 67
0

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.

Rob
  • 415,655
  • 72
  • 787
  • 1,044