We have .NET code (C#) that writes to a SQLite database, which is then read by an iOS (iPhone) app with objective-c.
The date format used in SQLite is NSTimeInterval (to NSDate with dateWithIntervalSince1970) because it’s efficient on the iPhone.
How can .NET DateTime be converted to NSTimeInterval so that when it is extracted with dateWithIntervalSince1970 the date is correct?
Notes:
1) I tried to search on how NSTimeInterval works fundamentally but only find this opaque documentation:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html
2) Although C# code would be ideal I’d be happy with pseudo-code that goes from 3 ints (year/month/day) to a double.
I think you mean
NSTimeInterval.NSTimeIntervalrepresents a span of time, in seconds, so its logical equivalent in .NET isSystem.TimeSpanrather thanSystem.DateTime. But, if you specify it as the span of time sinceJanuary 1, 1970 00:00:00 GMT, which is what you get with-timeIntervalSince1970, then the conversion between it andSystem.DateTimebecomes possible.To convert between
System.DateTimeand a POSIX timestamp (which is whatNSTimeIntervalis in this situation, plus subsecond precision), you probably want something like this:To go the other way: