NSDateFormatter adds AM/PM even when using a fixed dateFormat string?

I'm having a strange issue with NSDateFormatter. I'm using a fixed dateFormat string of yyyyMMdd-HHmmss, but on my iOS device (only; its fine in Simulator or on Mac) I get an extra AM/PM added to the string, and also missing leading zeros for the time portion:


Code Block language
dateFormat: "yyyyMMdd-HHmmss"
result 20200725-22454 PM


where I'd expect (and elsewhere get)

Code Block language
dateFormat: "yyyyMMdd-HHmmss"
result 20200725-022454


any ideas what I could be missing? Both my Mac and my test phone are set to 12-hour time, but as I understand it local settings should not matter when providing a dateFormat string...

It's a well-known behavior.

Class NSDateFormatter

Working With Fixed Format Date Representations

...
When working with fixed format dates, such as RFC 3339, you set the dateFormat property to specify a format string. For most fixed formats, you should also set the locale property to a POSIX locale ("enUSPOSIX"), and set the timeZone property to UTC.
You need to set the locale as specified in the doc when using fixed format.

NSDateFormatter adds AM/PM even when using a fixed dateFormat string?
 
 
Q