views:

96

answers:

2

Hi All,

In my project i am getting "2008-02-01T10:03:23.793-06:00" this date format in string i have to convert into NSDate i am using

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];

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

NSDate* dateFromString = [dateFormatter dateFromString:@"2008-02-01T10:03:23.793-06:00"];

But when i am print date value using NSLog i am getting value as null.

Please help me out

Thank You

A: 

NSDateFormatter won't be able to parse it, because the timezone doesn't conform with RFC 822 or GMT standard. The problem is on the last ":" to have it you need the "GMT".

The date that you have respects the RFC 3339.

You will need to use a NSFormatter to parse it. You should use getObjectValue:forString:errorDescription:

Set the string @"yyyy-MM-dd'T'HH:mm:ss.SSSZ".

vfn
A: 

I think you need to set a locale for the formatter too. Have a look here

epatel