Steven Schafer Steven Schafer - 1 year ago 98
Objective-C Question

How do I NSLog an NSDate?

With the code pasted below, I am trying to log an NSDate. What am I doing wrong here?

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"YYYY-MM-dd"];
NSDate *todaysDate;
todaysDate = [NSDate date];
NSLog(@"Todays date is %@",formatter);

Answer Source

All you have to do is:

  NSLog(@"Todays date is %@",[formatter stringFromDate:todaysDate]);