views:

151

answers:

1

I have dates that are being stored in a database by core data. I then am using php to print out this date information but the date is coming out wrong.

When I store Aug 2, 2009 in core data it comes out in the php as Fri, August 4, 1978. How do I fix the conversion?

+1  A: 

I'm guessing a bit here, but the limited evidence fits the hypothesis...

NSDate has an absolute reference date of 1 Jan 2001 (GMT).

PHP time() uses the Unix Epoch date of 1 Jan 1970 (GMT).

It looks like you have an offset of 31 years - or rather 978307200 seconds.

(NSTimeInterval) delta = [[NSDate dateWithTimeIntervalSinceReferenceDate:0] timeIntervalSince1970];

Solution would be to either create your dates in Cocoa with the reference date of 1970, or to add/subtract the offset in Cocoa or PHP.

James

James