Here’s how I’m setting it up:
self.df = [[NSDateFormatter alloc] init];
[self.df setFormatterBehavior:NSDateFormatterBehavior10_4];
[self.df setDateFormat:@"posted: MM-dd-YYYY"];
Here is how I am calling it in my trace:
NSLog(@"%@, %@, %@, %@", df, post.date, [post.date class], [df stringFromDate:post.date]);
Here’s the output:
<NSDateFormatter: 0x8440d60>, 2012-02-09 12:40:38 +0000, __NSDate,
It’s not null, it’s “”.
The post class with the date property is autogenerated by core data. I can’t see how that makes a difference, but it’s the only thing that seems even slightly unusual.
You cannot use setDateFormat like that.
I tried this code and it worked:
Now, you can do: