NULL value when using NSDateFormatter

Posted by David A Gibson on Stack Overflow See other posts from Stack Overflow or by David A Gibson
Published on 2010-04-14T09:46:06Z Indexed on 2010/04/14 9:52 UTC
Read the original article Hit count: 540

Filed under:
|
|
|

Hello,

I am using the following code to try and display in a time in a table cell.

TimeSlot *timeSlot = [timeSlots objectAtIndex:indexPath.row];
NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
[timeFormat setDateFormat:@"%1m/%1d/%Y"];
NSLog(@"Time: %@", timeSlot.time);
NSDate *mydate = timeSlot.time;
NSLog(@"Time: %@", mydate);
NSString *theTime = [timeFormat stringFromDate:mydate];
NSLog(@"Time: %@", theTime);

The log output is this:

  • 2010-04-14 10:23:54.626 MyApp[1080:207] Time: 2010-04-14T10:23:54
  • 2010-04-14 10:23:54.627 MyApp[1080:207] Time: 2010-04-14T10:23:54
  • 2010-04-14 10:23:54.627 MyApp[1080:207] Time: (null)

I am new to developing for the iPhone and as it all compiles with no errors or warnings I am at a loss as to why I am getting NULL in the log. Is there anything wrong with this code?

Thanks

© Stack Overflow or respective owner

Related posts about iphone

Related posts about nsdate