Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the iPhone SDK Core Data system store date types to sqlite?

I used core data to do this:

NSManagedObjectContext *m = [self managedObjectContext];
Foo *f = (Foo *)[NSEntityDescription insertNewObjectForEntityForName:@"Foo" 
                                                        inManagedObjectContext:m];
f.created_at = [NSDate date];
[m insertObject:f];

NSError *error;
[m save:&error];

Where the created_at field is defined as type "Date" in the xcdatamodel.

When I export the sql from the sqlite database it created, created_at is defined as type "timestamp" and the values look like:

290902422.72624

Nine digits before the . and then some fraction.

What is this format? It's not epoch time and it's not julianday format.

Epoch would be:

1269280338.81213

julianday would be:

2455278.236746875 (notice only 7 digits before the . not 9 like I have)

How can I convert a number like 290902422.72624 to epoch time? Thanks!

like image 897
Andrew Arrow Avatar asked Mar 22 '10 17:03

Andrew Arrow


People also ask

How does SQLite store date time?

Date and Time Datatype. SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values: TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.

What is difference between Core Data and SQLite in iOS?

The short answer is simple. Core Data is a framework for managing an object graph. SQLite is a relational database.

Where does Core Data store Data?

The persistent store should be located in the AppData > Library > Application Support directory.

Why Core Data is better than SQLite?

SQLite is a database while Core Data is not. Core Data is a framework which manages an object graph. Core Data is fast in terms of operation. It don't hit the database every time for operations.


1 Answers

Just add 978307200 to the number in core data and you'll get normal timestamp

NSString *coreDataTimestamp =@"464615485.832736"; //string of timestamp in coredata
NSTimeInterval timestamp = [coreDataTimestamp doubleValue] + 978307200;
like image 99
Andrew Marin Avatar answered Oct 19 '22 23:10

Andrew Marin