0

I have to get a date from a string. So I am using the below code:

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

//Fri Mar 09 15:31:35 CST 2012
[formatter setDateFormat:@"EEE MMM d HH:mm:ss ZZZ yyyy"];
NSDate *date = [formatter dateFromString:[newDict objectForKey:@"eventDate"]];
NSLog(@"aDate is %@",[newDict objectForKey:@"eventDate"]);

eventDate is coming in the format aDate is Fri May 18 12:00:37 IST 2012 but date is coming null.

I know it is a small issue but I am really stuck up with it.

Justin Boo
  • 10,132
  • 8
  • 50
  • 71
dead_soldier
  • 429
  • 1
  • 5
  • 18

2 Answers2

2

Your input string can be parsed with a format of @"EEE MMM d HH:mm:ss VVV yyyy".

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57
-1

Try adding this before the dateFromString: call:

[formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_IN"]];
joverboard
  • 335
  • 1
  • 3
  • 13
  • This code will leak if you are not using ARC, however you can add an `autorelease` in there if you are still working with manual memory management. – joverboard Jun 22 '12 at 14:29