iosobjective-cnsdate

dateFormatter string for date type 2013-03-24T02:15:23-08:00 using Objective C


I want to convert 2013-03-24T02:15:23-08:00 string to NSDate object. I tried formatter string yyyy-MM-ddTHH:mm:ss-Z, but the NSDate object is coming as nil.

Below is my code for conversion:

 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
        [dateFormatter setDateFormat:@"yyyy-MM-ddTHH:mm:ss-Z"];
        NSDate* date = [dateFormatter dateFromString:image.dateTaken];

Solution

  • There are two errors in the date format string:

    This should work:

    [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"];