NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
fmt.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy";
NSDate *stutsCreatedDate = [fmt dateFromString:_created_at];
以上是格式化时间格式为指定格式的代码,但是通过运行发现最后一句得到的nsdate永远都是nil ,查询无数文章最终解决。代码修改为
NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
fmt.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy";
[fmt setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
NSDate *stutsCreatedDate = [fmt dateFromString:_created_at];