转换成 字符串
NSDate convert to NSString:
1.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
2.
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
3.
NSString *strDate = [dateFormatter stringFromDate:[NSDate date]];
4.
NSLog(@"%@", strDate);
5.
[dateFormatter release];
2。 字符串转换成NSSdate:
NSString convert to NSDate:
1.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
2.
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
3.
NSDate *date = [dateFormatter dateFromString:@"2010-08-04 16:01:03"];
4.
NSLog(@"%@", date);
5.
[dateFormatter release];
标签:dateFormatter,NSDateFormatter,yyyy,date,NSString,NSDate,互转
From: https://blog.51cto.com/u_548275/6160127