幕后:核心数据日期与31年抵消存储?
问题描述:
我知道,“没有用户可维修的部件” ......但我很好奇:幕后:核心数据日期与31年抵消存储?
在核心数据sqlite3的DB,看来我可以在日期ZDATE内得到像这样:
sqlite> select datetime(ZDATE,'unixepoch','31 years','localtime') from ZMYCLASS;
2003-12-11 19:00:00
2009-12-31 19:00:00
2009-01-24 19:00:00
2011-01-01 19:00:00
2009-10-03 20:00:00
...
Unix Epoch我得到,但为什么31年?
答
核心数据的保存日期,相对于基准日,这是2001年1月1日(EPOCH后的第31年,在评论中指出)
下面是一些代码从表中的日期进行解码,如果它是对你有用。
NSNumber *time = [NSNumber numberWithDouble:(d - 3600)];
NSTimeInterval interval = [time doubleValue];
NSDate *online = [NSDate dateWithTimeIntervalSinceReferenceDate:interval];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MM/dd/yyyy HH:mm:ss.SSS"];
NSLog(@"result: %@", [dateFormatter stringFromDate:online]);
看看+ dateWithTimeIntervalSinceReferenceDate:
+3
1月1日在源码中找到的十进制转换为真正的约会时间, 2001年是Unix纪元后的31年。这听起来像是对我的回答。 – paulmelnikow
+0
好点,编辑我的答案来指定。 +1给你 – mprivat
可以使用http://www.epochconverter.com/coredata – J3RM