-3

This can be very simple question, but I'm unable to convert "January 1, 1987" type string into "dd-MM-yyyy" format which is returning from Facebook for the value "user_birthday". Please Help! Thank you in advance.

  • This same question has been asked dozens of times. http://stackoverflow.com/questions/15218565/iphone-how-to-convert-today-date-and-time-to-gmtformat10-digits http://stackoverflow.com/questions/14217650/converting-date-format http://stackoverflow.com/questions/12530701/converting-strangely-formatted-date-to-a-nicely-formatted-date – borrrden Apr 03 '13 at 05:57
  • I was going through them, but could not figure it out.Anyway thanks alot! – user2239002 Apr 03 '13 at 09:27

1 Answers1

1

Very simple : Need two dateFormatter formats:

NSString *string=@"January 1, 1987"; // type string into "dd-MM-yyyy"
NSDateFormatter *dateFormatter=[NSDateFormatter new];
[dateFormatter setDateFormat:@"MMM dd, yyyy"];
NSDate *date=[dateFormatter dateFromString:string];
NSLog(@"%@",date);
[dateFormatter setDateFormat:@"dd-MM-yyyy"];
NSString *stringDate=[dateFormatter stringFromDate:date];
NSLog(@"%@",stringDate);
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140