iphone NSDate转换问题
在我的图表Api for facebook ..
In my graph Api for facebook..
我收到这些数据..
来自Json .. updated_time=2011-05-17T14:52:16 + 0000;
I am getting this data..
from Json.."updated_time" = "2011-05-17T14:52:16+0000";
我正在使用此代码将其转换为有效的日期格式
and I am using this code to convert it into valid date format
NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
//2010-12-01T21:35:43+0000
[df setDateFormat:@"yyyy-mm-ddHH:mm:ssZZZZ"];
NSDate *date = [df dateFromString:[[forTable valueForKey:@"updated_time"] stringByReplacingOccurrencesOfString:@"T" withString:@""]];
[df setDateFormat:@"eee MMM dd, yyyy hh:mm"];
pastDate = [df stringFromDate:date];
NSLog(@"and the date string is %@",pastDate);
它在控制台给我这个结果
and it is giving me this result in the console
,日期字符串是Mon 01 17,2011 08:22
虽然json值正在给出我是May的日期。这段代码给了我1月的日期
though json value is giving me the date of May.this code is giving me the date January
谁能告诉我这里发生了什么?
can anyone tell me what is happening here?
看起来您的日期格式字符串没有考虑字母T - 您可能应该在撇号之间附加文字文本,只是为了安全起见。尝试:
It looks like your date format string isn't taking the letter "T" into account – and you should probably be enclosing literal text between apostrophes, just to be safe. Try:
[df setDateFormat:@yyyy' - 'MM' - 'dd'T'HH':'mm':'ssZZZZ ];