2

I have a date string like 2012/10/11 21:46:31 +0000

And I have tried almost maximum number of combinations but everytime I am getting NSDate as null.

NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
[fmt setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
NSDate *fromDate = [fmt dateFromString:fromDateString];

I am using iOS6

where fromDateString= 2012/10/11 21:46:31 +0000

IronManGill
  • 7,222
  • 2
  • 31
  • 52
Tariq
  • 9,861
  • 12
  • 62
  • 103

1 Answers1

4

Try the following (include the timezone string):

NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
[fmt setDateFormat:@"yyyy/MM/dd HH:mm:ss Z"];
NSDate *fromDate = [fmt dateFromString:@"2012/10/11 21:46:31 +0000"];
Wolfgang Schreurs
  • 11,779
  • 7
  • 51
  • 92