Error when inserting NSDate to CoreData

守給你的承諾、 提交于 2019-12-20 04:08:57

问题


    NSDateFormatter *dt = [[NSDateFormatter alloc] init];
    [dt setDateFormat:@"dd-MM-yyyy"];
    NSDate *bdate = [dt dateFromString:@"02-02-2013"];
    [nouContacte setValue:bdate forKey:@"birthday"];

I don't understand why that code doesn't work. It inserts 9 different digits like 318366000. I can insert strings, "booleans", numbers, but i can't with date.

birthday field in coredata is date type.

any idea?


回答1:


For a "Date" attribute, Core Data stores the "number of seconds since 1 January 2001, GMT" in the SQLite file, i.e. what you get with

[bdate timeIntervalSinceReferenceDate]

For example, 2011-02-02 19:00:00 +0000 is stored as the number 318366000.

But that is an implementation detail and you should not worry about it. When reading objects from the SQLite file, the number is converted back do an NSDate.



来源:https://stackoverflow.com/questions/21516696/error-when-inserting-nsdate-to-coredata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!