I have a valid Date() object I am trying to convert. I've looked at other SO posts and it seems like my code should do it:
private func getHoursMinutesString(date:Date) -> String
{
let formatter = Foundation.DateFormatter()
formatter.dateFormat = "HH:mm"
return formatter.string(from: date)
}
However, the time returned is always "00:00". If a put a fresh Date() object in, it will return the right time. I'm wondering what might be wrong with my Date() object that you could see? Here is an lldb printout of the data:
As you can see, the formatter is a valid object. The date (I think) is a valid date object. When passed through the formatter it becomes "00:00" but it works fine with a new Date() object.
Is there anything in the date
object that stands out as improperly formatted or missing? Or is there an extra step I am missing in my formatter?
Update After doing research, setting a timezone fixes the problem. Why, I don't know!