Posted By

espinallab on 02/23/10


Tagged

NSDate NSDateFormatter


Versions (?)

Who likes this?

8 people have marked this snippet as a favorite

zingo
jodm
avanadra
dannolan
sb
nwiegmann
AndreyZarembo
cnathan


Date from String


 / Published in: Objective C
 

URL: http://stackoverflow.com/questions/2311421/convert-string-to-nsdate

  1. NSString *dateStr = @"20100223";
  2.  
  3. // Convert string to date object
  4. NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
  5. [dateFormat setDateFormat:@"yyyyMMdd"];
  6. NSDate *date = [dateFormat dateFromString:dateStr];
  7.  
  8. // Convert date object to desired output format
  9. [dateFormat setDateFormat:@"EEEE MMMM d, YYYY"];
  10. dateStr = [dateFormat stringFromDate:date];
  11. [dateFormat release];

Report this snippet  

You need to login to post a comment.