views:

623

answers:

2

hi, it is possible to convert in iphone sdk (obj-c) a string to nsdate. thank you

+4  A: 

You'll want to take a look at NSDateFormatter. Determine the format of the date string and then use dateFromString: to convert the string to an NSDate object.

Giao
+2  A: 
NSString *dateStr = @"20100223";

// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyyMMdd"];
NSDate *date = [dateFormat dateFromString:dateStr];  

// Convert date object to desired output format
[dateFormat setDateFormat:@"EEEE MMMM d, YYYY"];
dateStr = [dateFormat stringFromDate:date];  
[dateFormat release];

Hope this will help you.

Suresh Kumar