I am trying to convert a am/pm format time to a 24 hour format time
6:35 PM to 18:35
I tried this piece of code on playground but it doesnt
Unfortunately apple priority the device date format, so in some cases against what you put, swift change your format to 12hrs
To fix this is necessary to use setLocalizedDateFormatFromTemplate instead of dateFormat an hide the AM and PM
let formatter = DateFormatter()
formatter.setLocalizedDateFormatFromTemplate("HH:mm:ss a")
formatter.amSymbol = ""
formatter.pmSymbol = ""
formatter.timeZone = TimeZone(secondsFromGMT: 0)
var prettyDate = formatter.string(from: Date())
You can check a very useful post with more information detailed in https://prograils.com/posts/the-curious-case-of-the-24-hour-time-format-in-swift