This question is not a copy of another: I have an issue that I don't find somewhere else.
I want to convert a date as String
to the Date
format. This String
date is supposed to be the same format as Date
because I used to upload it as String in a database. Here is what the String
date looks like:
"2017-03-10 22:16:00 +0000";
I'm trying to convert it like that:
let df: DateFormatter = DateFormatter()
df.dateFormat = "yyyy-MM-dd hh:mm:ss Z"
print(beginDateString) // "2017-03-10 22:16:00 +0000"
let beginDate = df.date(from: beginDateString)
print(beginDate) // App crashs here because of nil value.
The issue is that it gives me a nil value for the variable beginDate
.
I also tried with other dateFormat
like this one: "yyyy-MM-dd hh:mm:ss"
but it still doesn't work.