Home > other >  Date has wrong format Swift
Date has wrong format Swift

Time:11-20

I'm struggling with a problem here, i try to send data to server and i keep getting response "Date has wrong format. Use one of these formats instead: YYYY-MM-DD."

Here is my code example:

let postString: [String: String] = [
    "key": randomString(of: 16),
    "username": number.text!,
    "first_name": name.text!,
    "last_name": surname.text!,
    "birth_date": year.text!   month.text!   day.text!,
    "password": password.text!,
    "email": emailOpt.text!
]

i want to know how i can change it to "right" format

CodePudding user response:

I think you can convert year.text! month.text! day.text! to this:

"\(year.text!)-\(month.text!)-\(day.text!)"
  • Related