从数据库接收到一串时间string,转换为其他格式,为此写了一个方法
<pre name="code" class="objc">-(NSString *) timeChange:(NSString *)timeString
{
NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
[inputFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[inputFormatter setDateFormat:@"EEE MMM dd HH:mm:ss Z yyyy"];
NSDate *inputDate = [inputFormatter dateFromString:timeString];
NSLog(@"date = %@", inputDate);
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc]init];
[outputFormatter setLocale:[NSLocale currentLocale]];
[outputFormatter setDateFormat:@"yyyy年MM月dd日 HH时mm分ss秒"];
NSString *timeChanged = [outputFormatter stringFromDate:inputDate];
NSLog(@"datestr = %@", timeChanged);
return timeChanged;
}