I need to convert a string date in the following format and while the date is returning correctly the time is not. The string being sent is "2022-08-16 02:07:11 America/Los_Angeles"
however I'm getting back 2022-08-16 09:07:11 +0000
. Can't understand why when the timezone is right and I'm also missing the America/Los_Angeles
despite using VV
in the formatter. How can I get the right format back?
I also thought this maybe a console print bug??
var stringToDate: Date {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.calendar = Calendar(identifier: .gregorian)
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = TimeZone(identifier: "America/Los_Angeles")!
dateFormatter.timeZone = TimeZone(identifier: "America/Los_Angeles")
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss VV"
let date = dateFormatter.date(from: self)
return date!
}