1

NSDateFormatter dateFromString returned a NSDate object before iOS v13 update. But in iOS v13 and v13.1 it returns nil NSDate object. How to resolve this issue?

changing Date & Time from "Settings -> General - > Date & Time" then Unticking 24-Hour Time resolves this error.

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

NSDate *date = [formatter dateFromString:@"2019-10-02 09:10:15"];

Expected a not nil *date

iOS v12 and older versions didn't have this issue, setting Locale was not mandatory to get the date formatted.

1 Answers1

3

I found a way to resolve this issue.

[formatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]];

@hyd00 setting a Locale your way also solves this issue. Thanks a lot.

[formatter setLocale:[NSLocale localeWithLocaleIdentifier:[NSLocale currentLocale].localeIdentifier]];