-4

I have a date i take from twitter :

  NSString *date=[twt objectForKey:@"created_at"];
  NSLog(@"%@",date);
  NSDateFormatter *df = [ [NSDateFormatter alloc] init]  ;
  [df setDateFormat:@"dd-MM-yyyy HH:mm:ss"];
  NSDate *newdate = [df dateFromString:date];
  NSLog(@"new: %@",newdate); //null

the date is : Thu Jun 12 20:56:53 +0000 2014 and i get null on the new date . What am i missing ?

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Curnelious
  • 1
  • 16
  • 76
  • 150

2 Answers2

1

The date formatting string you've shared sure does't look like it matches the date you're getting from Twitter. The docs for dateFromString state...

A date representation of string interpreted using the receiver’s current settings. If dateFromString: can not parse the string, returns nil.

Read up!

http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns

CrimsonChris
  • 4,651
  • 2
  • 19
  • 30
1

the date formatter for that format (Thu Jun 12 20:56:53 +0000 2014) would be this:

"EEE MMM d HH:mm:ss Z yyyy"

rather than this "dd-MM-yyyy HH:mm:ss".

Community
  • 1
  • 1
holex
  • 23,961
  • 7
  • 62
  • 76