I am converting the UTC date to a string. when the date convert to string successfully it is showing "2023-07-11 9:07:51U202fPM".dont know why its added unicode in the string.
func toString(formateType type: DateFormate) -> String {
let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone(abbreviation: "UTC") //TimeZone(abbreviation: "UTC")
dateFormatter.dateFormat = type.rawValue
return dateFormatter.string(from: self)
}
Date Format – "yyyy-MM-dd HH:mm:ss"
can you please help me how to fix this
2
Answers
Check this code
//you need to call like this
let date = toString(formatTpe: "yyyy-MM-dd HH:mm:ss")
I have attach screenshot of result
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS"
dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
let utcDate = Date()
let utcString = dateFormatter.string(from: utcDate)
print(utcString)