I have a string date:
newsItem.Date = @"2/8/2012 7:21:09 PM";
And the code:
NSString* dateString = newsItem.Date;
NSDateFormatter* firstDateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[firstDateFormatter setDateFormat:@"MM/dd/yyyy hh:mm:ss a"];
NSDate* date = [firstDateFormatter dateFromString:dateString];
In simulator a got the proper date like:
2012-02-08 17:21:09 +0000
But on device the date = nil. WHY?
Possibly the device uses different locale, in which the string is not a valid date. Try adding the following:
before calling
dateFromString.