If system date is in 24 hours format. I want to set selected date and time in 12 hours format with AM/PM to textfield as input view. I am trying to convert selected date and time but its giving me 24 hours format. Can anyone please help me. Here is my code for conversion:
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm"
let dateAsString = dateFormatter.string(from: datePickerView.date)
dateFormatter.dateFormat = "yyyy-MM-dd h:mm a"
let date = dateFormatter.date(from: dateAsString)
let DateIn12 = dateFormatter.string(from: date!)
print("12 hour formatted Date:", DateIn12)
Replace your code to convert 24 hour date into 12 hour format with following code