The backend provides me with date in the format: "2018-09-07 01:00:00 am" The timezone of this date is UTC. Now I have to convert it into local timezone. The function I am using is:
func getLocalDate(dateString: String) -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss a"
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
dateFormatter.locale = Locale.current
let dt = dateFormatter.date(from: dateString)
dateFormatter.timeZone = TimeZone.current
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss aZ"
return dateFormatter.string(from: dt!)
}
With this, the date is being converted into UTC first and then into local timezone so I don't get the desired result. How do I set the timezone of that date as UTC, without any conversion?
EDIT: The output i am getting is 2018-09-07 05:45:00 AM+0545 but the expected output is 2018-09-07 06:45:00 AM+0545