I'm trying to convert a string:
2018-01-18 13:04:42 +0000
to something like
January, 18, 2018
using DateFormatter
but it fails. I have tried other questions (this, this and this).
This is my simple code which prints nil
:
let str = "2018-01-18 13:04:42 +0000"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMMM, dd, YYYY"
dateFormatter.locale = Locale.current
let mydate = dateFormatter.date(from: str)
print(mydate)