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
Use this function for date conversion , its working fine when your device in 24/12 hr formate
func convertDateFormater(fromFormate:String,toFormate:String,_ dateString: String) -> String{
let formatter = DateFormatter()
formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") as Locale
formatter.dateFormat = fromFormate
let date = formatter.date(from: dateString)
formatter.dateFormat = toFormate
return date != nil ? formatter.string(from: date!) : ""
}