幕后花絮:核心数据日期以 31 年偏移存储?

2024-03-24

我知道,“里面没有用户可维修的部件”......但我很好奇:

在 Core Data 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]);

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html

看一眼+ dateWithTimeIntervalSinceReferenceDate:

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

幕后花絮:核心数据日期以 31 年偏移存储? 的相关文章

随机推荐