我想将一个nsstring转换为nsdate .i创建了一个全局变量,其中我保存从datepicker中选取的日期,然后将此变量转换为nsdate为datefromstring函数。但字符串没有被转换成日期。可能是什么问题。如何将nsstring转换为iphone中的nsdate
TTimePickercontroller:
This is the class in which i have the code for the picker
-(NSString *)convertDueDateFormat{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:[NSLocale currentLocale]];
[dateFormatter setFormatterBehavior: NSDateFormatterBehavior10_4];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
dateString = [dateFormatter stringFromDate:datePicker.date];
return dateString;
//dateString is an nsstring variable that has been declared globally.
}
TAddAlarmController.
this is another class in which i want to convert the dateString varibale into nssdate
-(IBAction)save{
timepicker = [[TTimePickerController alloc]init];
NSDateFormatter* df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"hh:mm"];
d = [df dateFromString:dateString];
NSLog(@"%@", d);
//Here i am using the dateFromString function and converting the string variable dateString into nsdate variable d .in dateString variable value is getting passed but in d the value is not getting passed.
}
Please help me in solving the problem.Thanks
的可能重复的[转换的NSString的NSDate](http://stackoverflow.com/questions/1809379/convert-nsstring-to-nsdate) –