Steven Schafer Steven Schafer - 2 months ago 17
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

All you have to do is:

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