let myDateFormat = DateFormatter()
let now = Date()

myDateFormat.dateFormat = "yyyy-MM-dd HH:mm:ss"
print(myDateFormat.string(from: now))       // 2021-10-05 13:05:35

myDateFormat.dateFormat = "MM/dd/yy h:mm a"
print(myDateFormat.string(from: now))       // 10/05/21 1:05 PM