What is the best way to deal with the NSDateFormatter locale “feechur”?

Duh!! Sometimes you have an “Aha!!” moment, sometimes it’s more of a “Duh!!” This is the latter. In the category for initWithSafeLocale the “super” init was coded as self = [super init];. This inits the SUPERCLASS of NSDateFormatter but does not init the NSDateFormatter object itself. Apparently when this initialization is skipped, setLocale “bounces off”, … Read more

String extensions toDate() is crash some device

Two solutions: Add en_US_POSIX locale for a fixed format. Use ISO8601DateFormatter (iOS 8+), the benefit is no locale, no date format, no time zone. func toDate() -> Date? { let dateFormatter = ISO8601DateFormatter() return dateFormatter.date(from: self) } In any case return an optional, fatalError() in production environment causes pretty bad user experience.

Format date with NSDateFormatter

Try this First You need to convert this string back to NSDate then again convert the NSdate to string using formatter. NSDateFormatter *dateFormatForDB = [[NSDateFormatter alloc] init]; [dateFormatForDB setDateFormat:@”dd-MM-yyyy HH:mm a”]; //Note capital H is 4 24-hour time format NSDate *aDate = [[[NSDate alloc] initWithTimeInterval:0 sinceDate:[dateFormatForDB dateFromString:aDateString]] autorelease]; if(aDate){ [formatter setDateFormat:@”MMM dd,yyyy”]; NSString *date = … Read more