I spent about an hour trying to figure out why this code wouldn’t give me a string with the current date and time:
NSDate *now = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSString *nowString = [[NSString alloc]initWithString:[dateFormatter stringFromDate:now]];
Turns out NSDateFormatter requires some formatting before returning the expected string. When I add these two lines after creating dateFormatter everything works fine:
What’s odd is that this requirement isn’t documented anywhere, as far as I can tell.
Am I missing something?