幕后:核心数据日期存储与31年抵消? [英] Behind The Scenes: Core Data dates stored with 31 year offset?

查看:119
本文介绍了幕后:核心数据日期存储与31年抵消?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,里面没有用户可以维护的部分...但我很好奇:

I know, "no user-serviceable parts inside" ... but I'm curious:

在Core Data sqlite3数据库中,在如下所示的ZDATE日期:

In a Core Data sqlite3 DB, it seems I can get at the date within a ZDATE like so:

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
...


$核心数据存储相对于参考日期的日期,但是为什么31年?

Unix Epoch I get, but why 31 years?

推荐答案

这是2001年1月1日(在EPOCH之后31年,在评论中指出)

Core Data stores dates relative to reference date, which is Jan 1st, 2001 (31 years after EPOCH as pointed out in the comments)

这里有一些代码来解码表中的日期,

Here's some code to decode the dates from the table, in case it is useful to you.

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:

这篇关于幕后:核心数据日期存储与31年抵消?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆