正确的方法来将NSString转换为iOS上的NSDate?

我一直在使用这种方法将常规NSString对象转换为NSDate,但尝试提交更新到苹果,它被拒绝。 在iOS中做这个的另一种方法是什么?

NSString *date_str = @"2011-08-12T12:20:00Z"; NSDate *the_date = [NSDate dateWithNaturalLanguageString:date_str locale:[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]]; 

提前致谢!

使用NSDateFormatter 。 简单的例子如下:

 ... NSString* dateString = "2011-08-12T12:20:00Z"; NSDateFormatter* fmt = [NSDateFormatter new]; [fmt setDateFormat:"yyyy-MM-dd'T'HH:mm:ss'Z'"]; NSDate* date = [fmt dateFromString:dateString]; [fmt release]; ... 

请注意,按照Unicode技术标准#35 , NSDateFormatter本身不支持单字母时区标识符(例如,z为祖鲁语时间)。