ios - NSDateFormatter dateFromString returns nil for MM/dd/yyyy -


I am using the same nsdateformatter style and string in many apps and functions but There is a function called the background thread, and when I apply the break point, then NSDate becomes zero when I use the datefromstring NSString * start = [dataDict objectForKey: @ "start_date"]; NSString * end; If (! [[Data Dict objectForKey: @ "end_date"] is EqualToString: @ ""]) {end = [dataet object object: @ "end_date"]; } Other {end = [statistics data item: @ "estimate_and_date"]; } NSDateFormatter * formatter = [[NSDateFormatter alloc] init]; [Format setDateFormat: @ "yyyy"]; // NSLocale * enUSPOSIXLocale = [[NSLocale alloc] // initWithLocaleIdentifier: @ "en_US_POSIX"]; // emphasis (enUSPOSIXLocale! = Zero); // [Format SettleCell: NUSPOSISSXLocalay]; // [Formator set time zone: [NSTimeZone timeJoinfire seconds from GMT: 0]]; NSDateFormatter * detailformatter = [[NSDateFormatter alloc] init]; [Details: setDateFormat: @ "MM / dd / yyyy"]; NSDateComponents * dateComponents = [NSDateComponents new]; DateComponents.year = Year; NSDate * newDate = [[NSCalendar current calendar] dateByAddingComponents: dateComponents toDate: _earliestDate options: 0]; NSString * Plain serial yer string = [formatter string string: newadet]; NSDT * Plain Serial DirectDate = [Formatter Debt Frostring: Pledanchrint YeerString]; NSDate * startDatePlain = [date of the format of the frame: start]; NSDate * endDatePlain = [formatter dateFromString: end];

enter image details here

why In case of date above, does the format return to Neil?

You are using the wrong format:

  NSDateFormatter * Formatter = [[NSDateFormatter alloc] init]; [Format setDateFormat: @ "yyyy"]; NSDate * startDatePlain = [date of the format of the frame: start]; NSDate * endDatePlain = [formatter dateFromString: end];   

You need to use your detailformatter :

  NSDateFormatter * detailformatter = [[NSDateFormatter alloc] init]; [Details: setDateFormat: @ "MM / dd / yyyy"]; NSDate * startDatePlain = [detailformatter dateFromString: start]; NSDate * endDatePlain = [detailformatter dateFromString: end];   

You've got the correct format set on detailformatter !

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -