Hello everyone
I have a specific date and time selected from a datepicker in iOS. I want to convert this date and time to UTC time.I used the function below for this.
func get_Date_time_from_UTC_time(string : String) -> String {
let dateformattor = DateFormatter()
dateformattor.dateFormat = "yyyy-MM-dd HH:mm:ss"
dateformattor.timeZone = NSTimeZone.init(abbreviation: "UTC") as TimeZone!
let dt = string
let dt1 = dateformattor.date(from: dt as String)
dateformattor.dateFormat = "yyyy-MM-dd HH:mm:ss ZZZ"
dateformattor.timeZone = NSTimeZone.local
return dateformattor.string(from: dt1!)
}
My location is in India. So when I pass the time like 2016-12-26 09:53:45, then it gives me UTC time like 2016-12-26 15:23:00 +0530. Now when I search google for UTC, it shows me the time as 4:32 AM 26 december. Please tell me why there is such a difference, and am I doing it right?
source
share