【发布时间】:2013-08-05 12:32:12
【问题描述】:
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 ];
【问题讨论】:
标签: ios objective-c nsstring nsdate