2011-08-22 147 views
1

我从一个Web服务,它看起来像这样得到一个日期字符串返回:iPhone日期格式查询

/Date(12924576000000+0000)/ 

谁能告诉我怎么这种格式为可读字符串?

谢谢。

回答

3

这里是我如何做它:

NSString * json_parsed_date = @"/Date(12924576000000+0000)/"; 
NSString* tsString = [json_parsed_date substringWithRange:NSMakeRange(6,10)]; 
NSNumber* timestamp = [NSNumber numberWithInteger:[tsString intValue]]; 
NSDate * dateObject = [NSDate dateWithTimeIntervalSince1970:[timestamp intValue]]; 

为人类可读的字符串:

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
[dateFormat setDateFormat:@"yyyy-MM-dd"]; 
NSString *theDate = [dateFormat stringFromDate:dateObject]; 
+1

验证。这是绝对正确的。 – Nitish

+1

感谢您的回答,这完美运作 – shaw2thefloor