iOS-字符串转换成NSDate后在转换成字符串

一.字符串转换成NSDate

NSDateFormatter*df = [[NSDateFormatter alloc]init];//格式化
[df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
[df setLocale:[[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"] ];
NSDate*date =[[NSDate alloc]init];
date =[df dateFromString:timeStr];

二.NSDate转换成字符串

NSDateFormatter* df2 = [[NSDateFormatter alloc]init];
[df2 setDateFormat:@"MM月dd日 HH:mm"];
NSString* str1 = [df2 stringFromDate:date];

你可能感兴趣的:(iOS-字符串转换成NSDate后在转换成字符串)