I want to convert the date from local to UTC and UTC to Local.
For example, April 1, 2015, 12:00 PM - UTC, then
April 1, 2015, 5:30 pm is local to me, but I get the opposite from him.
let dateFormatter2 = DateFormatter()
dateFormatter2.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"[![enter image description here][1]][1]
dateFormatter2.timeZone = NSTimeZone.local
let date2 = dateFormatter2.date(from: "2015-04-01T12:00:00")
dateFormatter2.timeZone = NSTimeZone(name: "UTC")! as TimeZone
let date3 = dateFormatter2.date(from: "2015-04-01T12:00:00")
I get April 1, 2015, 5:30 pm in UTC and April 1, 2015, 12:00 as a local

source
share