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:
Date/Time parsing in iOS: how to deal (or not deal) with timezones?
Actually, date value in JSON response is:
created_at":"Mon, 28 May 2012 11:20:29 +0000"
Date variable is nil when receiving value by [df dateFromString:[twitter objectForKey:@"created_at"]];
Many thanks
i found that the "created_at" attribute in the twitter Json response is in this format:
so i used this formatter :
it's working fine ;)
Right formatter value is:
for:
To validate the format you're using, create a string from a date:
Compare this with the date from your JSON response and you should be able to see where your format is wrong.
In Swift
Following Method Return How many time before twit aris.
try this format if the month is abbreviated (Sept) :
and
if the month name is written out (September).
the full list of format specifiers.
I also had to change the locale
output