Dateformatter with "dd-MMM-yyyy" for September month returning date as "01-Sept-2022" for new version of iOS and for old its returning as "01-Sep-2022"
Why its returning 4 character abbreviation even after requested for 3 character
Should be worth a bug report, at least against documentation.
No.
The expected behaviour of DateFormatter (NSDateFormatter in Objective-C) is that it will render and parse dates in a way that makes sense to the user. This can change:
-
From release to release, as Apple imports new versions of CLDR
-
From region to region
-
From user to user, because users can override their region’s default settings
The only exception to this is if you set the locale to to en_US_POSIX.
So, if you’re working with fixed-format dates:
-
Try to use
ISO8601DateFormatter, which was specifically designed for that task. -
If that doesn’t meet your needs, use
DateFormatterand pin the locale toen_US_POSIX.
This is well documented — originally in QA1480 NSDateFormatter and Internet Dates but since then it’s been rolled into the official DateFormatter docs — but the shape of the API means that folks continue to fall into this trap (r. 33988168).
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"