Sebastian Boldt
Sebastian Boldt

Reputation: 5321

How to convert a RFC3339-String into a NSDate

i am trying to convert a RFC3339 formatted String Object to the corresponding NSDateObject : A received String looks like this : 2012-10-29T00:00:00+01:00 I tried to use a NSDateFormatter but i dont know the correct specifiers ? Any Ideas how to do this the right way ?

NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
[dateFormat setDateFormat:@"yyyy-MM-ddThh:mm:ss???????"]; // ?????
NSDate *date = [dateFormat dateFromString:startAtString];

Upvotes: 0

Views: 513

Answers (1)

Giuseppe Mosca
Giuseppe Mosca

Reputation: 1333

Inside one of my project I have this routine:

-(NSDate *)convertUTCStringToDate:(NSString *)utcDateString {
     NSDateFormatter *df = [[NSDateFormatter alloc]init];
     df.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss";
     return [df dateFromString:utcDateString];
}

Upvotes: 3

Related Questions