NSDateFormatter - Date parsing problem from Twitter JSON API

I am trying to convert a string from a Twitter API result to an NSDate object using NSDateFormatter. I found that NSDateFormatter simply returns the current date / time of my machine. Any help would be greatly appreciated!

This is what the line looks like in my function:

Sat, Dec 11 2010 01:35:52 +0000

And here is the function:

+(NSDate*)convertTwitterDateToNSDate:(NSString*)created_at
{
    // Sat, 11 Dec 2010 01:35:52 +0000
    static NSDateFormatter* df = nil;

    df = [[NSDateFormatter alloc] init];
    [df setTimeStyle:NSDateFormatterFullStyle];
    [df setFormatterBehavior:NSDateFormatterBehavior10_4];
    [df setDateFormat:@"EEE, d LLL yyyy HH:mm:ss Z"];

    NSDate* convertedDate = [df dateFromString:created_at];     
    [df release];

    return convertedDate;
}

And now the date is back:

2010-12-10 17:58:26 -0800

At the moment, this is the date and time of my computer.

* ! * DateFormater, . , , ( , - ), , .

+3
1

, . +0000 , -0800. , , , .

, ​​ [ ], , , . NSDate , , .

( , )

+1

Source: https://habr.com/ru/post/1779700/


All Articles