datetime – 幕后:Core数据日期存储31年偏移量?

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

一个核心数据sqlite3数据库中,看起来我可以在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

看看dateWithTimeIntervalSinceReferenceDate:

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...