Search code examples
objective-cnsdatenspredicateunix-timestamp

NSPredicate: NSLog of predicate using NSDate seems wrong


Where is my error?

Following lines of code:

NSPredicate* someTestPredicate = [NSPredicate predicateWithFormat:@"departureTime >= %@", [NSDate date]];
    NSLog(@"Some Test Predicate: %@", someTestPredicate);

Results in:

2019-04-02 20:19:55.671894+0200 [9402:337625] Some Test Predicate: departureTime >= CAST(575921995.671820, "NSDate")

And this timestamp refers to: 04/01/1988 @ 6:19pm (UTC)

So why is the year so wrong? What do I do wrong?


Solution

  • Your math is correct, but the internal reference date used by NSDate is 2001-01-01, not 1970-01-01 as seen in many other places for UNIX timestamps. That's also why NSDate has timeIntervalSinceReferenceDate and timeIntervalSince1970.