Search code examples
objective-cnsdatensdateformatter

How to convert NSstring to Nsdate


I am getting response from service that

"created_at" = "Thu Jul 06 07:26:23 +0000 2017";

i want to convert the string into Nsdate format i do not know how to do it


Solution

  • Try this:

    NSString *dateString = @"Thu Jul 06 07:26:23 +0000 2017";
    
    NSDate *date =[[NSDate alloc] init];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"EEE MMM dd hh:mm:ss Z yyyy";
    date = [ dateFormatter dateFromString:dateString];