I'm trying to get a string with the current date using the following:
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
NSLog(@"%@", [formatter stringFromDate:[NSDate date]]);
However NSLog is n开发者_如何学JAVAot outputting any strings (I'm getting a blank in the console)? What am I doing wrong?
You also have to tell the date formatter the output format you want to use. For example:
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateStyle:NSDateFormatterLongStyle];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
NSLog(@"%@", [formatter stringFromDate:[NSDate date]]);
See the documentation for more (e.g. setDateFormat:
). Sorry for not mentioning this in my other answer.
精彩评论