swift NSDateFormatter not working

The 24-hour format is “HH”, not “hh”.

The reason that it works in the Playground may be
that user defined settings can override the 12/24-format choice, compare
What is the best way to deal with the NSDateFormatter locale “feechur”?.
To be on the safe side, set the “en_US_POSIX” locale for the date formatter:

formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")

// Swift 3:
formatter.locale = Locale(identifier: "en_US_POSIX")

Leave a Comment