Xcode 9.0.1 · Swift 4 · iPhone 5s
To recreate the problem I'm getting in my app, I've created a single view application and added the following three lines of code to ViewController.viewDidLoad()
:
let formatter = DateFormatter()
formatter.dateFormat = "HH:mm"
print(formatter.string(from: Date()))
The app is then run on my iPhone and I get the following results:
If the phone is set to 24 hour time (Settings > Date & Time > 24 Hour Time) the code prints "07:45" in the console.
If 24 hour time is switched off at the settings then "7:45 am" is printed in the console.
Question: How do I make the output consistent with the formatter rather than the phone settings?