将string转换为自定义格式的NSDate

可能重复:
NSString到NSDate
iPhone:如何将“yyyyMMddThhmmss”格式string转换为NSDate?

如何将此格式转换为NSDate?

我的stringdate格式是: yyyy-m-d'T'H:m:ss (间隔之间没有空格)。

更新:

 2012-11-06T12:17:22.947 would be the string that I'd like to convert to NSDate 

只要将这个方法粘贴到你的.m文件中,然后用你的stringDate调用这个方法。

 -(NSDate *)convertStringToDate:(NSString *) date { NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; NSDate *nowDate = [[[NSDate alloc] init] autorelease]; [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"]; date = [date stringByReplacingOccurrencesOfString:@"+0000" withString:@""]; nowDate = [formatter dateFromString:date]; // NSLog(@"date============================>>>>>>>>>>>>>>> : %@", nowDate); return nowDate; }