What I want to do: Take the timestamp from my database and convert it to the timezone of the user.
My code:
let tryItNow = "\(model.timestampName)"
let format = DateFormatter()
let date = format.date(from: tryItNow)
format.timeZone = .current
format.dateFormat = "yyyy-MM-dd HH:mm:ss Z"
let dateString = format.string(from: date!) //Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
print(dateString)
The problem: I guess Xcode tells me, that date
is empty, which can't really be true. I get the timestamp from a struct and this whole thing is in a function, that's why its called model.timestampName
.
What I tried: Searching on the internet, here on stack overflow (most tutorials are 3 years old and I did not find anything for my specific case).