I have a struct that should give me the correct date from the server but it is nil or time has different with local time like the server return 2021-09-08T20:52:47.001Z but when I want to convert it to swift date it is nil with my code.
import Foundation
struct TimeManager{
static func editTime(withTime time:String) {
let serverDateFormatter:DateFormatter = {
let result = DateFormatter()
result.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSS"
result.timeZone = .current
return result
}()
let date = "2021-09-08T20:52:47.001Z"
let dateformat = serverDateFormatter.date(from: date)
print(dateformat)
}
}
I have tested all links in StackOverflow. I have tested this link also link