-3

I am receiving TimeString from server in such format - "2012-04-23T14:00:00.511Z" and for some reason I get nil when trying to convert that into NSDate object by doing following

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd HH:mm:ss a"];
NSDate *myDate = [df dateFromString: @"2012-04-23T14:00:00.511Z"];

What might be the issue?

the-noob
  • 1,322
  • 2
  • 14
  • 19
artumi
  • 105
  • 8

1 Answers1

1

Your code should be like,

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSDate *myDate = [df dateFromString: @"2012-04-23T14:00:51Z"];
NSLog(@"%@",myDate);
Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
  • Thank You very much. I figured this out lately. Sorry for not upvoting, previous guys lowered my rating by downvoting my question, and i am now eligible even to upvote and save good answers for myself :) – artumi May 26 '16 at 13:24
  • you're welcome.... :) If it is work and you feel that it is helping then accept the answer so other people having similar issue can use it... :) – Ketan Parmar May 26 '16 at 13:28