I’m looking to turn an NSDate into a string in the following format:
YYYY-MM-DD HH:MM:ss
I’ve tried all sorts of tricks with NSDateFormatter, and so far, this snippet looks like my best bet:
NSDateFormatter *format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"YYYY-MM-DD HH:MM:ss"];
NSString *stringThing = [format stringFromDate:thing];
Unfortunately, it seems not to work:
(lldb) po stringThing
(NSString *) $17 = 0x06b54190 2012-07-195 11:07:29
(lldb) po thing
(NSDate *) $18 = 0x06b2f150 2012-07-13 15:29:29 +0000
I’m wracking my brain, trying to explain, what’s going on. Is this a correct method for using DateFormatter?
You are using the date formatter correctly. I guess your date format isn’t correct. Try this: