I'm working on date formatter, I got a response of date from server in string type, which I convert into date format but what I want to do is to convert a date and then manage according to local time.
For example, if 12/06/2017, 06:48:03
is a date from server and i'm from Pakistan so it gives me a date and time according to GMT+5 which is 12/06/2017, 11:48:03
Same as from India it gives me a date and time according to GMT+5:30 which is 12/06/2017, 12:18:03
Here is a source code
public class func converServerTimeStampToDate (_ timeStamp: String) -> Date {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM/dd/yyyy, hh:mm:ss a"
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
let localDate = dateFormatter.date(from: timeStamp)
dateFormatter.timeZone = TimeZone.current
dateFormatter.dateFormat = "MM/dd/yyyy, hh:mm:ss a"
// return dateFormatter.string(from: localDate!)
return dateFormatter.date(from:dateFormatter.string(from:
localDate!))!
}
Any help would be appreciated !!