Behind The Scenes: Core Data dates stored with 31 year offset?

前端 未结 1 1890
春和景丽
春和景丽 2020-12-03 01:29

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

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

         


        
相关标签:
1条回答
  • 2020-12-03 02:08

    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

    Take a look at + dateWithTimeIntervalSinceReferenceDate:

    0 讨论(0)
提交回复
热议问题