iphone - CoreData sqlite3 db - populating timestamp column with python script -
i have coredata model backed sqllite db. want populate db initial data.
i have been using python far , has been working well. bit isn't working inserting dates. understand coredata stores dates in epoch format inserting them via python this:
time.mktime(datetime(2012, 7, 1, 12, 30, 30).timetuple()) however, doesn't give me correct date when data loaded via coredata. ideas on how format date read in correctly via coredata?
*note: realise people recommend doing via small app uses same model rather using python script, find python syntax more concise constructing , inserting lots of objects.
e.g. can call methods insert data this:
insertdata(con, 1, 1, 'data 1', 'description') vs objective-c long-winded method calls:
[self insertdata withcon:con id: 1 i2:1 val:@"data 1", desc:@"description"];
core data appears use 1 january 2001, gmt reference date (same nsdate method timeintervalsincereferencedate) , not 1970, mktime function in python, you'd have calculate timestamp based on that.
this entirely undocumented of course, , i'd agree dpjanes' answer approach bad idea.
if really want this, construct appropriate timestamp in python this:
import time datetime import datetime ref = time.mktime(datetime(2001, 1, 1, 0, 0, 0).timetuple()) = time.time() - ref
Comments
Post a Comment