My device used to have no problem returning the correct date from NSDate, but now all of a sudden, it isn’t working. I’ve rebooted my device, nothing changes. NSDate returns a date from 1970.
I started noticing this strange behavior when using an app I wrote (only on my device, simulator works fine), where a call to [NSDate date] returned some bizarre date from 1970. I was so puzzled that I tried creating a brand new test project. After creating the project, I simply added the following one line of code in the app delegate’s application:didFinishLaunchingWithOptions: message:
NSLog(@"Current Date: %@", [NSDate date]);
The log shows the following:
1970-01-12 00:04:53.-66 BP_DateTest[112:707] Current Date: 1970-01-12 04:04:53 +0000
My iPhone is currently running iOS 4.3.5 and this is an iPhone 4 device.
When I use the iOS calendar app, everything looks fine, it shows the current date correctly. I went into settings, and checked the international settings, and the calendar is set to Gregorian with United States format.
Please – does anyone have a clue what this is all about? It used to work just fine, so I have no idea what has happened.
The
1970-01-12 00:04:53output in the debugger says that your device is set to 1970.Check under
Settings->General->Date & Time->Set Date & Time