I'm trying to format a string(ex. Tue, 16 Jan 2018 | 05:34 PM) to date and then convert it back to string(ex. 2018-01-16 17:34:00) with different format by using following code.
let dateFormatterOne = DateFormatter()
dateFormatterOne.dateFormat = "E, d MMM yyy | hh:mm a"
dateFormatterOne.locale = Locale(identifier: "en_US_POSIX")
let dateFromString = dateFormatterOne.date(from: string)
let dateFormatterTwo = DateFormatter()
dateFormatterTwo.dateFormat = "yyyy-MM-dd HH:mm:ss"
let dateString = dateFormatterTwo.string(from: dateFromString!)
This seems to be working well in simulator but when I tested it on an iPod Touch running iOS 9 it doesn't give date in the first conversion so it becomes nil and crashes.