I want to convert following string into NSDate format
2012-04-29T08:20:04Z
Please help me. How I can achieve this.
I want to convert following string into NSDate format
2012-04-29T08:20:04Z
Please help me. How I can achieve this.
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!!!
here's a possible same question and some solution :
you can make your own format to fit your request..
hope this helps ..