How to format Facebook/Twitter dates (from the JSON feed) in Objective-C

前端 未结 8 975
有刺的猬
有刺的猬 2020-12-13 02:39

For my iPhone application...

I am looking for a way to format the Facebook created_time JSON property value.

\"created_time\": \"2010-12-0

8条回答
  •  时光说笑
    2020-12-13 03:11

    Just to complicate things a bit, the JSON response of the Twitter Search API currently returns a date format (inherited from Summize) which is something like:

    @"Sun, 05 Jun 2011 12:25:47 +0000"
    

    To convert this to NSDate, use:

    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
    [dateFormatter setDateFormat:@"eee, dd MMM yyyy HH:mm:ss ZZZZ"];
    NSDate *date = [dateFormatter dateFromString:@"Sun, 05 Jun 2011 12:25:47 +0000"];
    

提交回复
热议问题