Note that there are some explanatory texts on larger screens.

plurals
  1. PODate formatter returns null
    text
    copied!<p>I am always getting a null from the date formatter. I tried examples in all the other questions and didn't help.</p> <pre><code> NSLog(@"Date is %@", summaryItem.SubmittedDate); NSLog(@"Formatted Date is %@", [df stringFromDate: summaryItem.SubmittedDate ]); BOOL isDate = [summaryItem.SubmittedDate isKindOfClass: [NSDate class]]; NSLog(@"Date %@ a date.", isDate ? @"is" : @"is not"); </code></pre> <p>Looking at the definition of SubmittedDate you have</p> <pre><code>@property (nonatomic, retain) NSDate *SubmittedDate; </code></pre> <p>I am initializing the Date Fomatter as so</p> <pre><code>- (void) initDateFormatter { if( df == nil ) { df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"MM/dd/yyyy"]; [df setDateStyle:NSDateFormatterShortStyle]; } } </code></pre> <ol> <li>Output to Log: <ul> <li>2012-11-21 10:00:41.650 Mobile_v2[4093:f803] Date is 11/21/2012 10:00:41 AM</li> <li>2012-11-21 10:00:41.651 Mobile_v2[4093:f803] Formatted Date is (null)</li> <li>2012-11-21 10:00:41.681 Mobile_v2[4093:f803] Date is not a date.</li> </ul></li> </ol> <p>Can anyone see what's wrong? Is my date format incorrect?</p> <p>Code in my SBJson class</p> <pre><code>NSString *newDate = (NSString *)[receivedObjects objectForKey:@"SubmittedDate"]; NSDate *submittedDate = [df dateFromString:newDate]; //(NSDate *) if ((NSNull *) submittedDate == [NSNull null]) { self.SubmittedDate = nil; } else { self.SubmittedDate = submittedDate; } </code></pre> <p>Actual value is "11/21/2012 10:47:54 AM"</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload