Twitter JSON API的NSDate格式器问题 [英] NSDate formatter issue with Twitter JSON API
本文介绍了Twitter JSON API的NSDate格式器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图格式化JSON响应日期值:
I'm trying to format JSON response date value:
NSDateFormatter *df = [[NSDateFormatter alloc] init];
//Wed Dec 01 17:08:03 +0000 2010
[df setDateFormat:@"eee, MMM dd HH:mm:ss ZZZZ yyyy"];
NSDate *date = [df dateFromString:[twitter objectForKey:@"created_at"]];
[df setDateFormat:@"dd/MM/yyyy"];
NSString *dateStr = [df stringFromDate:date];
我按照此问题的指示操作:
I follow instructions of this question:
实际上,JSON响应中的日期值为:
Actually, date value in JSON response is:
created_at":"Mon, 28 May 2012 11:20:29 +0000"
通过接收值时日期变量为nil [df dateFromString:[twitter objectForKey:@created_at]];
非常感谢
推荐答案
如果月份缩写:
[df setDateFormat:@"EEE, d MMM y HH:mm:ss Z"];;
和
[df setDateFormat:@"EEE, d MMMM y HH:mm:ss Z"];
if月份名称写出(9月)。
if the month name is written out (September).
the full list of format specifiers.
我还必须更改区域设置
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]];
[df setDateFormat:@"EEE, d MMM y HH:mm:ss Z"];
NSDate *date = [df dateFromString:@"Mon, 28 May 2012 11:20:29 +0000"];
[df setDateFormat:@"dd/MM/yyyy"];
NSString *dateStr = [df stringFromDate:date];
NSLog(@"%@",dateStr);
输出
28/05/2012
这篇关于Twitter JSON API的NSDate格式器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文