将字符串转换成NSDate格式:
(一) NSString * string = @"20140111152832";
NSDateFormatter * formatter = [[NSDateFormatter alloc]init];[formatter setDateFormat:@"yyyyMMddHHmmss"];
NSDate * date = [formatter dateFromString:string];
[formatter setDateFormat:@"yyyy-MM-dd:HH-mm-ss"];
NSString * result = [formatter stringFromDate:date];
(二) NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
[dateFormatter1 setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *date1 = [dateFormatter1 dateFromString:@"2010-08-04 16:01:03"];
NSLog(@"1111111111111111%@", date1);
[dateFormatter1 release];
将NSData转换成NSString格式
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat@"yyyy-MM-dd HH:mm:ss"];
NSString *strDate = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"8888888888888%@", strDate);
[dateFormatter release];