2

I have a date string like this "2013-04-25T08:00:00.000+0000" what is the right way to read it as a date.

I tried all this:

How to convert NSDate into unix timestamp iphone sdk?

iOS - Proper formatting of timestamps between mySQL (apache) and iOS (NSDate)

converting timestamp to nsdate format

and I tried this too:

+(NSDate *)dateFromUTCTimeStamp:(NSString *)dateString
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss'Z'";
    NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
    [dateFormatter setTimeZone:gmt];
    NSDate *timeStamp = [dateFormatter dateFromString:dateString];
    return timeStamp;
}

everything returns nil, I know I am making a simple mistake but need some help.

Community
  • 1
  • 1
Satheesh
  • 10,998
  • 6
  • 50
  • 93
  • 6
    `dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSz";` would do fine. Refer the comments of this [answer](http://stackoverflow.com/a/17010081/767730) – Anupdas Jun 13 '13 at 13:44
  • @Anupdas Thanks a lot, worked like a charm. – Satheesh Jun 13 '13 at 13:52

0 Answers0