0

I want to convert following string into NSDate format

2012-04-29T08:20:04Z

Please help me. How I can achieve this.

The iOSDev
  • 5,237
  • 7
  • 41
  • 78
Pradeep
  • 73
  • 8

2 Answers2

0

Try this:

-(NSDate *)dateFromString:(NSString *)string
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormat setLocale:locale];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss z"];

NSDate *date1 = [dateFormat dateFromString:string];  
if(!date1) date1= [NSDate date];
[dateFormat release];
[locale release];

return date1;
}

Tell me if it helps!!!

Deviator
  • 688
  • 3
  • 7
0

here's a possible same question and some solution :

NSString to NSDate

you can make your own format to fit your request..

hope this helps ..

Community
  • 1
  • 1
iremk
  • 677
  • 1
  • 5
  • 16