Inconsistent Date Output and 24-Hour Format Issue on iOS 15.4 and iOS 16.3.1

When using the following code:

[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];

The output on iOS 15.4 is "2023-05-02T03:40:15.748Z", while the output on iOS 16.3.1 is "2023-05-02T上午3:41:19.606Z". This inconsistency in the output is causing issues with my app's functionality.

I would also like to add that it is important for the output to always maintain the 24-hour format. This consistency is crucial for my app's functionality, and any suggestions on how to ensure that the output always displays the time in 24-hour format would be greatly appreciated. Thank you.

I have found the root cause of the issue. The system settings were overriding the locale information. After setting

dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];

the issue was resolved.

You might also consider NSISO8601DateFormatter (link) which is designed to work with non-localized internet dates like this with less trouble than using NSDateFormatter.

Also see this thread for further discussion of this topic.

Inconsistent Date Output and 24-Hour Format Issue on iOS 15.4 and iOS 16.3.1
 
 
Q