NSDate日期格式转换

iOS如何转这种日期格式 Fri Apr 14 00:00:00 CST 2017
NSString *cstString = @"Fri Apr 14 00:00:00 CST 2017";

NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
[inputFormatter setDateFormat:@"EEE MMM dd HH:mm:ss 'CST' yyyy"];
inputFormatter.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"en_US"];

NSDate *formatterDate = [inputFormatter dateFromString:cstString];
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *newDateString = [outputFormatter stringFromDate:formatterDate];

NSLog(@"%@", newDateString);

你可能感兴趣的:(NSDate日期格式转换)