我已经在文本文件中存储了一个日期,我可以正确地读出它。这个字符串的输出是
“下午 6:00”
就这样。但是,当我这样做时:
//First, set the first datePicker
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
NSString *breakfastTimeStartLocation = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"breakfastTimeStart.txt"];
NSString *time = [NSString stringWithContentsOfFile:breakfastTimeStartLocation encoding:NSUTF16StringEncoding error:nil];
NSLog(@"Loaded time is %@", time);
NSDate *startDate = [dateFormatter dateFromString:time];
NSLog(@"Start Date = %@", startDate);
在此,time
返回"6:00 PM"
,但startDate
返回"(null)"
我一定错过了一些东西,为什么这在世界上不起作用?
谢谢。