I have stored a date in a text file, and I can read it out properly. The output for this string is
“6:00 PM”
Just like that. However, when I do:
//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);
In this, time returns the "6:00 PM", but startDate returns "(null)"
I must be missing something, why in the world does this not work?
Thanks.
That’s not the right way to init an
NSDateFormatter, the designated initializer isinitWithDateFormat:allowNaturalLanguage:Thus: