I have been following the multiple examples to convert my iso date string to a local date String and have got the following working:
func ISOStringToLocal(ISODateString: String) -> String {
let dateFormatterGet = DateFormatter()
dateFormatterGet.timeZone = NSTimeZone(name: "UTC")! as TimeZone
dateFormatterGet.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" //Input Format with seconds
// dateFormatter.dateFormat = " yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" //Input Format with milliseconds
let dateFormatterPrint = DateFormatter()
dateFormatterPrint.dateFormat = "dd-MMM-yyyy hh:mm:ss"
if let date = dateFormatterGet.date(from: ISODateString) {
return dateFormatterPrint.string(from: date)
} else {
return ""
}
}
How do I allow the the dateFormatterGet
to accept another input format for milliseconds as well as seconds?