![objective-c-nsstring-nsdate-conversion](https://www.memorylack.com/wp-content/uploads/2010/08/objective-c.png)
NSDate convert to NSString:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *strDate = [dateFormatter stringFromDate:[NSDate date]]; NSLog(@"%@", strDate);[dateFormatter release];
Result:
2010-08-04 16:01:03
NSString convert to NSDate:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSDate *date = [dateFormatter dateFromString:@"2010-08-04 16:01:03"]; NSLog(@"%@", date);[dateFormatter release];
Result:
2010-08-04 16:01:03 +0800