I am trying to pass in a string and return it as a date. However when I pass the string in, the date returned is coming back as an UTC date. I tried the top solutions from this question but could not find the correct solution for Swift 4:
I figured this was the best approach, but still returns in UTC:
func getDateFromDexReturnDateString(aDate : String) -> Date?
{
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
dateFormatter.timeZone = TimeZone.current //Thought these two lines would solve it, but doen't
dateFormatter.locale = Locale.current
return dateFormatter.date(from: aDate)!
}
Edit:
Here is a picture of what is happening:
notice that the date that I pass in (aDate) is different than the date that is being returned (dateToReturn). Why wouldn't it be the same? I figured it was an UTC issue, but I may need to edit title of question. Thanks for any help.