したがって、設定した形式は [df setDateFormat:@"HH:mm, MMMM d, yyyy"]; です。
文字列 myString は @"2012-11-07 15:22:06" です
=> 一致しない
---他の回答に関するあなたのコメントを読んで集めたもの:
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
NSString *myString = @"2012-11-07 15:22:06"; //yyyy-MM-dd HH:mm:ss
//convert to date
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-DD HH:mm:ss"];
NSDate *myDate = [df dateFromString:myString];
NSLog(@"%@", myDate); //2012-01-07 14:22:06 +0000
//output it in natural language
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[df setTimeStyle:NSDateFormatterNoStyle];
[df setDateStyle:NSDateFormatterMediumStyle];
[df setLocale:usLocale];
NSLog(@"%@", [df stringFromDate:myDate]); //Jan 7, 2012
}
}