【发布时间】:2011-09-06 04:30:05
【问题描述】:
我想将 nsstring 转换为 nsdate 。我创建了一个全局变量,我保存从 datepicker 中选择的日期,然后将此变量转换为 nsdate 我们使用 datefromstring 函数。但是字符串没有转换为 date。什么可能是问题所在。
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
【问题讨论】:
标签: iphone objective-c