Arpit Parekh Arpit Parekh - 2 months ago 9
iOS Question

"2016-09-07T13:00:00.000Z" could not find date format

I have date in NSString as

2016-09-07T13:00:00.000Z


I could not convert it to
NSDate
.

I tried below
NSDateFormatter
code,

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss";
NSLog(@"Date: %@",[dateFormatter dateFromString:self.newsArticle.release_date]);


Please give me some guide.

Answer

Change your date formate to yyyy-MM-dd'T'HH:mm:ss.sss'Z'.

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.sss'Z'";
NSLog(@"Date: %@",[dateFormatter dateFromString:@"2016-09-07T13:00:00.000'Z'"]);