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

前端之家收集整理的这篇文章主要介绍了datetime – 幕后:Core数据日期存储31年偏移量?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我知道,“内部没有用户可维修的部件”…但我很好奇:

在一个核心数据sqlite3数据库中,看起来我可以在ZDATE这样的日期得到这样的结果:

  1. sqlite> select datetime(ZDATE,'unixepoch','31 years','localtime') from ZMYCLASS;
  2. 2003-12-11 19:00:00
  3. 2009-12-31 19:00:00
  4. 2009-01-24 19:00:00
  5. 2011-01-01 19:00:00
  6. 2009-10-03 20:00:00
  7. ...

Unix Epoch我得到了,但为什么31年?

核心数据存储相对于参考日期的日期,即2001年1月1日(EPOCH在评论中指出的31年)

以下是一些解码表中日期的代码,以防对您有用。

  1. NSNumber *time = [NSNumber numberWithDouble:(d - 3600)];
  2. NSTimeInterval interval = [time doubleValue];
  3. NSDate *online = [NSDate dateWithTimeIntervalSinceReferenceDate:interval];
  4. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  5. [dateFormatter setDateFormat:@"MM/dd/yyyy HH:mm:ss.SSS"];
  6.  
  7. NSLog(@"result: %@",[dateFormatter stringFromDate:online]);

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

看看dateWithTimeIntervalSinceReferenceDate:

猜你在找的Bash相关文章