NSString
转换NSDate
返回null
。
原始字符串输出“ 2013-07-16T18:42:56+02:00 ”但是当我尝试转换为NSDate
它时返回“null”
这是我的代码:
// original string
NSString *str = [timeStamp objectAtIndex:indexPath.row];
// convert to date
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
//[dateFormat setDateFormat:@"YYYY-MM-dd'T'HH:mm:ss'+11:00'"];
[dateFormat setDateFormat:@"YYYY-MM-dd'T'HH:mm:ssZZZ"]; // updated from Stavash's post below. Still null is outputted for the date though
[dateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"Australia/Melbourne"]];
NSDate *dte = [dateFormat dateFromString:str];
cell.timeStampLabel.text = [NSString stringWithFormat:@"%@",dte ];