There are plethora of choices of Date format conversion you can use.
My favorite is RFC 3339 because it creates least possible confusion among date formats and it is completely suitable for PHP as well.
extension Date {
init?(rfc3339String: String) {
self.init()
let localeId = "en_US_POSIX"
let rfc3339DateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let fmt = DateFormatter()
fmt.locale = Locale(identifier: localeId)
fmt.dateFormat = rfc3339DateFormat
fmt.timeZone = TimeZone.current
self = fmt.date(from: rfc3339String)!
}
func rfc3339String() -> String {
let localeId = "en_US_POSIX"
let rfc3339DateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
let fmt = DateFormatter()
fmt.locale = Locale(identifier: localeId)
fmt.dateFormat = rfc3339DateFormat
fmt.timeZone = TimeZone.current
return fmt.string(from: self)
}
}