Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSDate being saved as timestamp in CoreData

I currently am saving dates in my iOS application in CoreData. In Core Data, my date attribute is of type "Date". In my NSManagedObjectSubclass file, the attribute is of type: NSDate (which is fine). The date in Core Data is being stored as: 2014/05/16 14:54:51 and when I check the actual values in my SQLite3 navigator, it is being stored in the form:

421959291.293972 for the date

How do I get the above value for the date, and is there a way to convert it back to the form: 2014/05/16 14:54:51? I'm asking this because I am trying to create a dataset via a CSV file, and want to make sure that all the values that I enter in the CSV file are converted correctly by Core Data/SQLite3 into the right format.

like image 727
syedfa Avatar asked Dec 12 '22 05:12

syedfa


1 Answers

if you are using sqlite3 as the command line tool, use the the datetime function to interpret the data, so for example

sqlite3> .schema
create table ZENTITY (... ZSTARTDATE TIMESTAMP, ...)
sqlite3> select datetime(zstartdate,'unixepoch','31 years') from ZENTITIY;

This should give the formatted timestamp stored in the entity table

The unix epoch/31 years arguments come from this stack overflow question. Behind The Scenes: Core Data dates stored with 31 year offset?

like image 134
Frank Cornelisen Avatar answered Jan 07 '23 08:01

Frank Cornelisen