幕后花絮:以 31 年偏移量存储的核心数据日期? [英] Behind The Scenes: Core Data dates stored with 31 year offset?

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

问题描述

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

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

在 Core Data sqlite3 DB 中,我似乎可以像这样获取 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
...

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

Unix Epoch I get, but why 31 years?

推荐答案

Core Data 存储相对于参考日期的日期,参考日期是 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天全站免登陆