我想將一個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) –