-1

I am trying to make a date from string but it returns null and I have no idea why...

 NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
 [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
 NSDate *dateFromApi = [dateFormatter dateFromString:@"0001-01-03T00:00:00+02:00"];

dueDate looks like this 0001-01-03T00:00:00+02:00

What am I doing wrong?

Barnee
  • 3,212
  • 8
  • 41
  • 53
CapeFurSeal
  • 183
  • 2
  • 13
  • In your date string you have +02:00 which is time zone, so your format is wrong. Try with "yyyy-MM-dd'T'HH:mm:ss'Z'" – arturdev Nov 18 '14 at 08:12
  • 1
    Check this: http://stackoverflow.com/questions/10057456/parsing-iso-8601-with-nsdateformatter – arturdev Nov 18 '14 at 08:20

1 Answers1

1

Turns out it was my date format. This work for me.

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.ZZZZ"];
NSDate *dateFromApi = [dateFormatter dateFromString:@"0001-01-03T00:00:00+02:00"];
CapeFurSeal
  • 183
  • 2
  • 13
  • @Rufflewind and Shan - how can this "not provide an answer to the question" when the OP is literally ANSWERING THEIR OWN QUESTION in this post?? In future please check the context of an answer before recommending deletion. – tom redfern Nov 18 '14 at 10:03
  • @Shan - see my comment above – tom redfern Nov 18 '14 at 10:04
  • 1
    @CapeFurSeal please remember to mark this as your answer when you are able to (after 2 days I think). – tom redfern Nov 18 '14 at 10:04
  • @TomRedfern sorry, at the time of review this question was not edited and shortly after that is has been edited, by adding pice if modified code, and i thought that it is fit to comment, but later after u commented i saw that it is answered by same owner – Shankar BS Nov 18 '14 at 10:19
  • @TomRedfern yeah. .. no worries .... :) any way thank you for re-checking it, i deleted my comment – Shankar BS Nov 18 '14 at 11:23