NSDate日期格式转换
2017-05-11 本文已影响25人
FANTASIED
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);